11<template >
22 <div class =" flex flex-col" >
33 <PageHeader :title =" title" >
4+ <Button
5+ v-if ="
6+ schemaName === 'Item' &&
7+ (!isSelectionMode || (isSelectionMode && selectedItems.length === 0))
8+ "
9+ @click =" toggleSelectionMode"
10+ >
11+ {{ t`Select` }}
12+ </Button >
13+ <div
14+ v-if ="
15+ isSelectionMode && schemaName === 'Item' && selectedItems.length > 0
16+ "
17+ class =" relative"
18+ >
19+ <Button class =" w-40" @click =" toggleDropdown" > Create Invoice </Button >
20+ <div
21+ v-if =" showDropdown"
22+ class ="
23+ absolute
24+ top-full
25+ mt-1
26+ bg-white
27+ border border-gray-300
28+ rounded
29+ shadow-lg
30+ z-10
31+ w-40
32+ "
33+ >
34+ <div
35+ v-for =" option in actionOptions"
36+ :key =" option.value"
37+ class =" px-4 py-2 hover:bg-gray-100 cursor-pointer text-sm"
38+ @click =" createInvoice(option.value)"
39+ >
40+ {{ option.label }}
41+ </div >
42+ </div >
43+ </div >
444 <Button ref =" exportButton" :icon =" false" @click =" openExportModal = true" >
545 {{ t`Export` }}
646 </Button >
1656 type =" primary"
1757 :padding =" false"
1858 class =" px-3"
19- @click =" makeNewDoc "
59+ @click =" handleMakeNewDoc "
2060 >
2161 <feather-icon name =" plus" class =" w-4 h-4" />
2262 </Button >
2767 :list-config =" listConfig"
2868 :filters =" filters"
2969 :can-create =" canCreate"
70+ :is-selection-mode =" isSelectionMode"
3071 class =" flex-1 flex h-full"
3172 @open-doc =" openDoc"
3273 @updated-data =" updatedData"
3374 @make-new-doc =" makeNewDoc"
75+ @selected-items-changed =" updateSelectedItems"
3476 />
3577 <Modal :open-modal =" openExportModal" @closemodal =" openExportModal = false" >
3678 <ExportWizard
@@ -49,6 +91,7 @@ import ExportWizard from 'src/components/ExportWizard.vue';
4991import FilterDropdown from ' src/components/FilterDropdown.vue' ;
5092import Modal from ' src/components/Modal.vue' ;
5193import PageHeader from ' src/components/PageHeader.vue' ;
94+
5295import { fyo } from ' src/initFyo' ;
5396import { shortcutsKey } from ' src/utils/injectionKeys' ;
5497import {
@@ -60,6 +103,8 @@ import { getFormRoute, routeTo } from 'src/utils/ui';
60103import { QueryFilter } from ' utils/db/types' ;
61104import { defineComponent , inject , ref } from ' vue' ;
62105import List from ' ./List.vue' ;
106+ import { Money } from ' pesa' ;
107+ import { ModelNameEnum } from ' models/types' ;
63108
64109export default defineComponent ({
65110 name: ' ListView' ,
@@ -90,10 +135,16 @@ export default defineComponent({
90135 listConfig: undefined ,
91136 openExportModal: false ,
92137 listFilters: {},
138+ isSelectionMode: false ,
139+ showDropdown: false ,
140+ selectedItems: [] as string [],
93141 } as {
94142 listConfig: undefined | ReturnType <typeof getListConfig >;
95143 openExportModal: boolean ;
96144 listFilters: QueryFilter ;
145+ isSelectionMode: boolean ;
146+ showDropdown: boolean ;
147+ selectedItems: string [];
97148 };
98149 },
99150 computed: {
@@ -113,6 +164,12 @@ export default defineComponent({
113164 canCreate(): boolean {
114165 return fyo .schemaMap [this .schemaName ]?.create !== false ;
115166 },
167+ actionOptions(): { value: string ; label: string }[] {
168+ return [
169+ { value: ' SalesInvoice' , label: ' Sales Invoice' },
170+ { value: ' PurchaseInvoice' , label: ' Purchase Invoice' },
171+ ];
172+ },
116173 },
117174 activated() {
118175 this .listConfig = getListConfig (this .schemaName );
@@ -160,9 +217,52 @@ export default defineComponent({
160217 const route = getFormRoute (this .schemaName , doc .name ! );
161218 await routeTo (route );
162219 },
220+ async handleMakeNewDoc() {
221+ await this .makeNewDoc ();
222+ },
163223 applyFilter(filters : QueryFilter ) {
164224 this .list ?.updateData (filters );
165225 },
226+ toggleSelectionMode() {
227+ this .isSelectionMode = ! this .isSelectionMode ;
228+ if (! this .isSelectionMode ) {
229+ this .showDropdown = false ;
230+ this .selectedItems = [];
231+ }
232+ },
233+ toggleDropdown() {
234+ this .showDropdown = ! this .showDropdown ;
235+ },
236+ async createInvoice(value : string ) {
237+ if (
238+ value === ModelNameEnum .SalesInvoice ||
239+ value === ModelNameEnum .PurchaseInvoice
240+ ) {
241+ const doc = fyo .doc .getNewDoc (value );
242+
243+ for (const itemName of this .selectedItems ) {
244+ const itemDoc = await fyo .doc .getDoc (' Item' , itemName );
245+
246+ const itemRow = {
247+ item: itemName ,
248+ rate: (itemDoc .rate as Money ) || fyo .pesa (0 ),
249+ quantity: 1 ,
250+ };
251+
252+ await doc .append (' items' , itemRow );
253+ }
254+
255+ const route = getFormRoute (value , doc .name ! );
256+ await routeTo (route );
257+ this .selectedItems = [];
258+ this .isSelectionMode = false ;
259+ this .showDropdown = false ;
260+ }
261+ },
262+
263+ updateSelectedItems(selected : string []) {
264+ this .selectedItems = selected ;
265+ },
166266 },
167267});
168268
0 commit comments