public function submit() { if ($this->prepare()) { $voucher = TransactionProcessor::ProcessPayment($this); if ($voucher) { //payment has gone trough; $supplier = Supplier::GetSupplier($this->supplierId); $grns = PurchaseInvoice::GetUnclearedInvoices($this->supplierId); if ($supplier->balance->amount > 0) { $amount = $this->amount->amount; } else { //if supplier has a prepayment (-ve ba) $amount = $this->amount->amount - $supplier->balance->amount; } $paidamt = floatval(0.0); $credgrn = ''; foreach ($grns as $grn) { if ($amount - $paidamt >= $grn->balance->amount) { $paidamt = $paidamt + $grn->balance->amount; $grn->credit(floatval($grn->balance->amount)); $credgrn .= $grn->id . ','; } elseif ($amount - $paidamt < $grn->balance->amount && $amount - $paidamt > 0.0) { $grn->credit(floatval($amount - $paidamt)); $credgrn .= $grn->id . ','; $paidamt = $paidamt + ($amount - $paidamt); } elseif ($amount == $paidamt) { break; } } $this->status = 1; $this->updateParticulars($credgrn); return $voucher; } else { return false; } } //make the journal entry based on the invoicing TX //Cr - Sales //Dr - Debtors [A/C Receivable] //Dr - Taxes Collectable }
public static function PurchaseInvoices() { $collection = PurchaseInvoice::GetAllInvoices($_GET['period'], $_GET['all']); echo ' <div class="logo"> <h5 style="margin-bottom:-15px;margin-top:0px;font-size:14px;">Date: ' . date('d/m/Y') . '</h5> <h4>ALL PURCHASE INVOICES</h4>'; if ($_GET['period'] != '' && $_GET['period']) { echo '<h5 style="margin-top:-10px">Period: ' . $_GET['period'] . '</h5>'; } echo '</div> <table class="table table-bordered table-striped" style="text-align:center;margin-left:0;margin-right:0;width:760px;font-size:12px;"> <thead class="title"> <tr> <td>DATE</td> <td>GRN NO</td> <td>INV NO</td> <td>COMPANY</td> <td>TOTAL</td> </tr> </thead> <tbody>'; $total = 0.0; $itms = 0; foreach ($collection as $item) { $party = Supplier::GetSupplier($item['party_id']); echo '<tr> <td>' . $item['date'] . '</td> <td>' . $item['id'] . '</td> <td>' . $item['invno'] . '</td> <td>' . $party->name . '</td> <td class="text-right" style="padding: 0 5px;"><script>document.writeln((' . $item['total'] . ').formatMoney(2, \'.\', \',\'));</script></td> </tr>'; $total += $item['total']; ++$itms; } echo '</tbody> </table> <div class="logo"> <p style="margin: 5px 0 0 5px">Total Invoices: <b>' . $itms . '</b></p> <p style="margin: 5px 0 0 5px">Total Invoiced: <b>Ksh. <script>document.writeln((' . $total . ').formatMoney(2, \'.\', \',\'));</script></b></p> </div>'; }
public function getUnclearedInvoices($supplierid) { if ($this->validateAdmin()) { echo json_encode(PurchaseInvoice::GetUnclearedInvoices($supplierid)); } else { echo 0; } }