Skip to content

Commit 21a71b8

Browse files
committed
Show the sent invoices total
1 parent 643d536 commit 21a71b8

File tree

3 files changed

+147
-8
lines changed

3 files changed

+147
-8
lines changed

module/expense.py

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def get_by_create_by(pid, create_by):
8181
''' Get by create_by '''
8282
return ExpenseDB().find({'pid': pid, 'create_by': create_by})
8383

84+
@staticmethod
85+
def get_has_sent(pid, budget_id):
86+
''' Get has sent and not canceled '''
87+
query = {'pid': pid, 'request.buid': budget_id}
88+
for raw in ExpenseDB().find(query, {'invoices': 1}):
89+
yield raw
90+
8491
@staticmethod
8592
def dl_format(pid):
8693
''' Make the download format(CSV) '''

templates/expense_lists.html

+135-8
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,48 @@ <h4>預算表資訊</h4>
143143
</tbody>
144144
</table>
145145
</div>
146+
<div class="content">
147+
<h4>已申請的單據</h4>
148+
</div>
149+
<div class="content">
150+
<div class="field" v-for="invoice, index in has_sent_invoices">
151+
<div class="field-body">
152+
<div class="field">
153+
<label class="label">[[ index+1 ]]. 發票號碼或收據</label>
154+
<div class="control">
155+
<input class="input" type="text" v-model="invoice.name" disabled>
156+
</div>
157+
</div>
158+
<div class="field">
159+
<label class="label">單據金額</label>
160+
<div class="field has-addons">
161+
<div class="control">
162+
<span class="select">
163+
<select v-model="invoice.currency" disabled>
164+
<option>TWD</option>
165+
<option>USD</option>
166+
</select>
167+
</span>
168+
</div>
169+
<div class="control">
170+
<input class="input" type="number" step="0.01" v-model.number="invoice.total" disabled>
171+
</div>
172+
</div>
173+
</div>
174+
<div class="field">
175+
<label class="label">單據狀況</label>
176+
<div class="control">
177+
<span class="select">
178+
<select v-model="invoice.status" disabled>
179+
<option value="sent">已寄出</option>
180+
<option value="not_send">還未寄出</option>
181+
</select>
182+
</span>
183+
</div>
184+
</div>
185+
</div>
186+
</div>
187+
</div>
146188
<form @submit.prevent="submit_expense">
147189
<div class="content">
148190
<h4>檢附單據</h4>
@@ -199,15 +241,47 @@ <h4>檢附單據</h4>
199241
</a>
200242
</div>
201243
<div class="content" v-if="invoices.length > 0">
202-
<h4 class="mt-5">申請金額</h4>
244+
<h4 class="mt-5">申請金額試算</h4>
203245
</div>
204-
<div class="field" v-if="invoices.length > 0">
205-
<label class="label">合計</label>
206-
<div class="field is-grouped is-grouped-multiline">
207-
<div class="control" v-for="[currency, total] in Object.entries(invoices_total)">
208-
<div class="tags has-addons">
209-
<span class="tag is-info">[[ currency ]]</span>
210-
<span class="tag is-success is-light">$[[ total.toLocaleString('en') ]]</span>
246+
<div class="field">
247+
<div class="field-body">
248+
<div class="field has-background-link-light p-3" v-if="invoices.length > 0">
249+
<label class="label">此次申請合計</label>
250+
<div class="field is-grouped is-grouped-multiline">
251+
<div class="control" v-for="[currency, total] in Object.entries(invoices_total)">
252+
<div class="tags has-addons">
253+
<span class="tag is-info">[[ currency ]]</span>
254+
<span class="tag is-success is-light" :class="{'is-danger': total < 0}">
255+
$[[ total.toLocaleString('en') ]]
256+
</span>
257+
</div>
258+
</div>
259+
</div>
260+
</div>
261+
<div class="field has-background-warning-light p-3" v-if="has_sent_invoices.length > 0">
262+
<label class="label">已申請合計</label>
263+
<div class="field is-grouped is-grouped-multiline">
264+
<div class="control" v-for="[currency, total] in Object.entries(has_sent_invoices_total)">
265+
<div class="tags has-addons">
266+
<span class="tag is-info">[[ currency ]]</span>
267+
<span class="tag is-success is-light" :class="{'is-danger': total < 0}">
268+
$[[ total.toLocaleString('en') ]]
269+
</span>
270+
</div>
271+
</div>
272+
</div>
273+
</div>
274+
<div class="field has-background-info-light p-3" v-if="has_sent_invoices.length > 0">
275+
<label class="label">預算餘額計算</label>
276+
<div class="field is-grouped is-grouped-multiline">
277+
<div class="control" v-for="[currency, total] in Object.entries(diff_invoices_total)">
278+
<div class="tags has-addons">
279+
<span class="tag is-info">[[ currency ]]</span>
280+
<span class="tag is-success is-light" :class="{'is-danger': total < 0}">
281+
$[[ total.toLocaleString('en') ]]
282+
</span>
283+
</div>
284+
</div>
211285
</div>
212286
</div>
213287
</div>
@@ -299,6 +373,9 @@ <h4 class="mt-5">設定撥款資訊</h4>
299373
default_invoice: {name: '', currency: 'TWD', total: 0, status: ''},
300374
invoices: [],
301375
invoices_total: {},
376+
has_sent_invoices: [],
377+
has_sent_invoices_total: {},
378+
diff_invoices_total: {},
302379
bank: {},
303380
bank_alert: 0,
304381
teams: [],
@@ -345,6 +422,38 @@ <h4 class="mt-5">設定撥款資訊</h4>
345422
}
346423
$expenselists.invoices_total[raw.currency] += raw.total;
347424
});
425+
this.cal_invoices_total();
426+
},
427+
sum_has_sent_invoices: function() {
428+
this.has_sent_invoices_total = {};
429+
$this = this;
430+
this.has_sent_invoices.forEach(function(raw) {
431+
if ($this.has_sent_invoices_total[raw.currency] === undefined) {
432+
$this.has_sent_invoices_total[raw.currency] = 0;
433+
}
434+
$this.has_sent_invoices_total[raw.currency] += raw.total;
435+
});
436+
},
437+
cal_invoices_total: function() {
438+
let base = {};
439+
base[this.modaldata.currency] = this.modaldata.total;
440+
let diff_total = Object.assign({}, base);
441+
442+
Object.entries(this.has_sent_invoices_total).forEach(function(raw) {
443+
if (diff_total[raw[0]] === undefined) {
444+
diff_total[raw[0]] = 0;
445+
}
446+
diff_total[raw[0]] -= raw[1];
447+
});
448+
449+
Object.entries(this.invoices_total).forEach(function(raw) {
450+
if (diff_total[raw[0]] === undefined) {
451+
diff_total[raw[0]] = 0;
452+
}
453+
diff_total[raw[0]] -= raw[1];
454+
});
455+
456+
this.diff_invoices_total = Object.assign({}, diff_total);
348457
},
349458
load: function() {
350459
++this.is_loading;
@@ -365,8 +474,26 @@ <h4 class="mt-5">設定撥款資訊</h4>
365474
});
366475
},
367476
create: function(item) {
477+
++this.is_loading;
368478
this.modaldata = Object.assign({}, item);
369479
this.create_expense();
480+
if (this.invoices.length == 0) {
481+
this.add_invoice();
482+
}
483+
this.has_sent_invoices = [];
484+
$this = this;
485+
axios.post('./', {casename: 'get_has_sent', buid: this.modaldata._id}).then(function(resp) {
486+
console.info(resp.data.data);
487+
resp.data.data.forEach(function(raw) {
488+
raw.invoices.forEach(function(invoice) {
489+
invoice['expense_id'] = raw._id;
490+
$this.has_sent_invoices.push(invoice);
491+
});
492+
});
493+
$this.sum_has_sent_invoices();
494+
$this.cal_invoices_total();
495+
--$this.is_loading;
496+
});
370497
},
371498
submit_expense: function() {
372499
++this.modaldata.is_loading;

view/team.py

+5
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,11 @@ def team_expense_index(pid, tid):
937937
expense_create.apply_async(kwargs={'expense': expense})
938938
return jsonify(data)
939939

940+
if data['casename'] == 'get_has_sent':
941+
data = Expense.get_has_sent(
942+
pid=project['_id'], budget_id=data['buid'])
943+
return jsonify({'data': list(data)})
944+
940945
return jsonify({}), 404
941946

942947

0 commit comments

Comments
 (0)