Ejemplo n.º 1
0
 private function processLatestInvoices()
 {
     try {
         $sql = 'SELECT id FROM invoices ORDER BY stamp DESC LIMIT 0,5';
         $res = DatabaseHandler::GetAll($sql);
         $sql2 = 'SELECT count(id) FROM invoices';
         $res2 = DatabaseHandler::GetOne($sql2);
         $invoices = [];
         foreach ($res as $invoice) {
             $invoices[] = SalesVoucher::GetInvoice(intval($invoice['id']));
         }
         $obj = new stdClass();
         $obj->invoices = $invoices;
         $obj->total = $res2;
         $this->latestInvoices = $obj;
     } catch (Exception $e) {
     }
 }
Ejemplo n.º 2
0
 public static function GetClientTransactions($cid, $category, $dates, $all)
 {
     if ($category == 1) {
         //Statement
         if ($all == 'true') {
             $sql = 'SELECT * FROM general_ledger_entries WHERE account_no = ' . intval($cid) . ' AND ledger_name = "Debtors" ORDER BY id DESC';
         } else {
             if ($dates != '') {
                 $split = explode(' - ', $dates);
                 $d1 = explode('/', $split[0]);
                 $d2 = explode('/', $split[1]);
                 $lower = $d1[2] . $d1[0] . $d1[1] . '000000' + 0;
                 $upper = $d2[2] . $d2[0] . $d2[1] . '999999' + 0;
                 $sql = 'SELECT * FROM general_ledger_entries WHERE account_no = ' . intval($cid) . ' AND ledger_name = "Debtors" AND stamp BETWEEN ' . $lower . ' AND ' . $upper . ' ORDER BY id DESC';
             }
         }
         try {
             $res = DatabaseHandler::GetAll($sql);
             $vouchers = [];
             foreach ($res as $tx) {
                 if ($tx['status'] == 1) {
                     if ($tx['effect'] == 'cr') {
                         if (stripos($tx['description'], 'Credit Note') !== false) {
                             $voucher = CreditVoucher::GetVoucher(intval($tx['transaction_id']));
                         } else {
                             $voucher = ReceiptVoucher::GetVoucher(intval($tx['transaction_id']));
                         }
                         if ($voucher) {
                             $vouchers[] = $voucher;
                         }
                     } else {
                         $voucher = SalesVoucher::GetVoucher(intval($tx['transaction_id']));
                         if ($voucher) {
                             $vouchers[] = $voucher;
                         }
                     }
                 } elseif ($tx['status'] == 3) {
                     $entry = new stdClass();
                     $entry->transactionId = $tx['transaction_id'];
                     $entry->date = $tx['when_charged'];
                     $entry->amount = $tx['amount'];
                     $entry->description = $tx['description'];
                     $sql2 = 'SELECT * FROM transactions WHERE id = ' . intval($tx['transaction_id']);
                     $res2 = DatabaseHandler::GetRow($sql2);
                     $entry->user = $res2['user'];
                     $entry->type = $res2['type'];
                     $vouchers[] = $entry;
                 }
             }
             return $vouchers;
         } catch (Exception $e) {
         }
     } else {
         //Quotations
         if ($all == 'true') {
             $sql = 'SELECT * FROM quotations WHERE client_id = ' . intval($cid) . ' ORDER BY id DESC';
         } else {
             $split = explode(' - ', $dates);
             $d1 = explode('/', $split[0]);
             $d2 = explode('/', $split[1]);
             $lower = $d1[2] . $d1[0] . $d1[1] . '000000' + 0;
             $upper = $d2[2] . $d2[0] . $d2[1] . '999999' + 0;
             $sql = 'SELECT * FROM quotations WHERE client_id = ' . intval($cid) . ' AND stamp BETWEEN ' . $lower . ' AND ' . $upper . ' ORDER BY id DESC';
         }
         try {
             $res = DatabaseHandler::GetAll($sql);
             $vouchers = [];
             foreach ($res as $quote) {
                 $vouchers[] = QuotationVoucher::initialize($quote);
             }
             return $vouchers;
         } catch (Exception $e) {
         }
     }
 }