Пример #1
0
 private static function getStats($date, $con)
 {
     $sales = SalesQuery::create()->filterByStatus('Active')->filterByDate(array('min' => $date->start, 'max' => $date->until))->withColumn('COUNT(Sales.Id)', 'sales_count')->withColumn('SUM(Sales.TotalPrice)', 'sales_total')->withColumn('SUM(CONVERT(Sales.TotalPrice, SIGNED) - CONVERT(Sales.BuyPrice, SIGNED))', 'sales_netto')->select(['sales_total', 'sales_count'])->find($con);
     $data['sales_count'] = isset($sales[0]['sales_count']) ? $sales[0]['sales_count'] : 0;
     $data['sales_total'] = isset($sales[0]['sales_total']) ? $sales[0]['sales_total'] : 0;
     $data['sales_netto'] = isset($sales[0]['sales_netto']) ? $sales[0]['sales_netto'] : 0;
     $purchase = PurchaseQuery::create()->filterByStatus('Active')->filterByDate(array('min' => $date->start, 'max' => $date->until))->withColumn('COUNT(Purchase.Id)', 'purchase_count')->withColumn('SUM(Purchase.TotalPrice)', 'purchase_total')->select(['purchase_count', 'purchase_total'])->find($con);
     $data['purchase_count'] = isset($purchase[0]['purchase_count']) ? $purchase[0]['purchase_count'] : 0;
     $data['purchase_total'] = isset($purchase[0]['purchase_total']) ? $purchase[0]['purchase_total'] : 0;
     // get current credit balance
     $credits = CreditQuery::create()->filterByStatus('Active')->useSalesQuery()->filterByDate(array('max' => $date->until))->endUse()->withColumn('CONVERT(Credit.Total, SIGNED) - CONVERT(Credit.Paid, SIGNED)', 'balance')->select(array('balance'))->find($con);
     $credit_total = 0;
     foreach ($credits as $credit) {
         if ($credit > 0) {
             $credit_total += $credit;
         }
     }
     $data['credit'] = $credit_total;
     // get current debit balance
     $debits = DebitQuery::create()->filterByStatus('Active')->usePurchaseQuery()->filterByDate(array('max' => $date->until))->endUse()->withColumn('CONVERT(Debit.Total, SIGNED) - CONVERT(Debit.Paid, SIGNED)', 'balance')->select(array('balance'))->find($con);
     $debit_total = 0;
     foreach ($debits as $debit) {
         if ($debit > 0) {
             $debit_total += $debit;
         }
     }
     $data['debit'] = $debit_total;
     $results['success'] = true;
     $results['data'] = $data;
     return $results;
 }
Пример #2
0
 public static function read($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('read_credit')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $page = isset($params->page) ? $params->page : 0;
     $limit = isset($params->limit) ? $params->limit : 100;
     $credits = CreditQuery::create()->filterByStatus('Active')->useSalesQuery()->leftJoin('SecondParty')->withColumn('SecondParty.Id', 'second_party_id')->withColumn('SecondParty.Name', 'second_party_name')->withColumn('Sales.Date', 'date')->endUse()->withColumn('CONVERT(Credit.Total, SIGNED) - CONVERT(Credit.Paid, SIGNED)', 'balance');
     if (isset($params->id)) {
         $credits->filterById($params->id);
     }
     if (isset($params->sales_id)) {
         $credits->filterBySalesId($params->sales_id);
     }
     if (isset($params->second_party_id)) {
         $credits->useSalesQuery()->filterBySecondPartyId($params->second_party_id)->endUse();
     }
     if (isset($params->second_party)) {
         $credits->useSalesQuery()->useSecondPartyQuery()->filterByName("%{$params->second_party}%")->endUse()->endUse();
     }
     if (isset($params->credit_status)) {
         switch ($params->credit_status) {
             case 'Lunas':
                 $credits->where('CONVERT(Credit.Total, SIGNED) - CONVERT(Credit.Paid, SIGNED) <= 0');
                 break;
             case 'Belum Lunas':
                 $credits->where('CONVERT(Credit.Total, SIGNED) - CONVERT(Credit.Paid, SIGNED) > 0');
                 break;
         }
     }
     $credits = $credits->select(array('id', 'sales_id', 'total', 'paid', 'second_party_id', 'second_party_name', 'date', 'balance'));
     foreach ($params->sort as $sorter) {
         $credits->orderBy($sorter->property, $sorter->direction);
     }
     $credits->orderBy('id', 'DESC');
     $credits = $credits->paginate($page, $limit);
     $total = $credits->getNbResults();
     $data = [];
     foreach ($credits as $credit) {
         $credit = (object) $credit;
         $credit->cash_back = $credit->balance < 0 ? abs($credit->balance) : 0;
         $data[] = $credit;
     }
     $results['success'] = true;
     $results['data'] = $data;
     $results['total'] = $total;
     return $results;
 }
Пример #3
0
 private static function getStats($params, $currentUser, $con)
 {
     $data = [];
     // sales this month
     $start = new \DateTime(Date('Y-m-01'));
     $until = new \DateTime(Date('Y-m-t'));
     $sales = SalesQuery::create()->filterByStatus('Active')->filterBySecondPartyId($params->customer_id)->filterByDate(array('min' => $start, 'max' => $until))->withColumn('COUNT(Sales.Id)', 'sales_count')->withColumn('SUM(Sales.TotalPrice)', 'sales_total')->select(['sales_count', 'sales_total'])->find($con);
     $data['sales_count_this_month'] = isset($sales[0]['sales_count']) ? $sales[0]['sales_count'] : 0;
     $data['sales_total_this_month'] = isset($sales[0]['sales_total']) ? $sales[0]['sales_total'] : 0;
     // sales this year
     $start = new \DateTime(Date('Y-01-01'));
     $until = new \DateTime(Date('Y-12-31'));
     $sales = SalesQuery::create()->filterByStatus('Active')->filterBySecondPartyId($params->customer_id)->filterByDate(array('min' => $start, 'max' => $until))->withColumn('COUNT(Sales.Id)', 'sales_count')->withColumn('SUM(Sales.TotalPrice)', 'sales_total')->select(['sales_count', 'sales_total'])->find($con);
     $data['sales_count_this_year'] = isset($sales[0]['sales_count']) ? $sales[0]['sales_count'] : 0;
     $data['sales_total_this_year'] = isset($sales[0]['sales_total']) ? $sales[0]['sales_total'] : 0;
     // get current credit balance
     $credits = CreditQuery::create()->filterByStatus('Active')->useSalesQuery()->filterBySecondPartyId($params->customer_id)->endUse()->withColumn('CONVERT(Credit.Total, SIGNED) - CONVERT(Credit.Paid, SIGNED)', 'balance')->select(array('balance'))->find($con);
     $credit_total = 0;
     foreach ($credits as $credit) {
         if ($credit > 0) {
             $credit_total += $credit;
         }
     }
     $data['credit'] = $credit_total;
     // get current debit balance
     $debits = DebitQuery::create()->filterByStatus('Active')->usePurchaseQuery()->filterBySecondPartyId($params->customer_id)->endUse()->withColumn('CONVERT(Debit.Total, SIGNED) - CONVERT(Debit.Paid, SIGNED)', 'balance')->select(array('balance'))->find($con);
     $debit_total = 0;
     foreach ($debits as $debit) {
         if ($debit > 0) {
             $debit_total += $debit;
         }
     }
     $data['debit'] = $debit_total;
     $data['customer_id'] = $params->customer_id;
     $results['data'] = $data;
     return $results;
 }
Пример #4
0
<head>
    <title>Print Nota Piutang <?php 
echo $id;
?>
</title>
    <link rel="stylesheet" type="text/css" href="print.css">
</head>
<script>
    setTimeout(function(){
        window.print();
        window.close();
    }, 10)
</script>
<body>
<?php 
$credit = CreditQuery::create()->filterByStatus('Active')->filterById($id)->useSalesQuery()->leftJoin('SecondParty')->withColumn('SecondParty.Id', 'second_party_id')->withColumn('SecondParty.Name', 'second_party_name')->withColumn('Sales.Date', 'date')->endUse()->select(array('id', 'sales_id', 'total', 'second_party_id', 'second_party_name', 'date'))->findOne($con);
if (!$credit) {
    throw die('Data tidak ditemukan.');
}
$credit = (object) $credit;
$payment = CreditPaymentQuery::create()->filterByStatus('Active')->filterByCreditId($credit->id)->withColumn('SUM(Paid)', 'total_paid')->select(array('total_paid'))->findOne($con);
$credit->paid = $payment;
$credit->balance = $credit->total - $credit->paid;
$credit->status = $credit->balance <= 0 ? 'Lunas' : $credit->balance;
$credit->cash_back = $credit->balance < 0 ? abs($credit->balance) : '-';
$creditPayments = CreditPaymentQuery::create()->filterByStatus('Active')->filterByCreditId($id)->leftJoin('Cashier')->withColumn('Cashier.Id', 'cashier_id')->withColumn('Cashier.Name', 'cashier_name')->select(array('id', 'date', 'paid', 'cashier_name'))->orderBy('date', 'ASC')->find($con);
?>

<div style="font-weight: bold; font-size: 15px; text-align: center;">
    <?php 
echo $info->client_name;
Пример #5
0
 /**
  * Returns a new ChildCreditQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildCreditQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildCreditQuery) {
         return $criteria;
     }
     $query = new ChildCreditQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Пример #6
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_sales')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $sales = SalesQuery::create()->findOneById($params->id, $con);
     if (!$sales) {
         throw new \Exception('Data tidak ditemukan');
     }
     $sales->setDate($params->date)->setSecondPartyId($params->second_party_id)->setBuyPrice($params->buy_price)->setTotalPrice($params->total_price)->setPaid($params->paid)->setCashierId($params->cashier_id)->setNote($params->note)->setStatus('Active')->save($con);
     // check wether this transaction is credit or not
     $balance = $params->paid - $params->total_price;
     if ($balance < 0) {
         $credit = CreditQuery::create()->filterBySalesId($sales->getId())->findOne($con);
         if (!$credit) {
             $credit = new Credit();
         }
         $credit->setSalesId($sales->getId())->setTotal(abs($balance))->setStatus('Active')->save($con);
     } else {
         $credit = CreditQuery::create()->filterBySalesId($sales->getId())->findOne($con);
         if ($credit) {
             $credit->setSalesId($sales->getId())->setTotal(0)->setStatus('Canceled')->save($con);
         }
     }
     $products = json_decode($params->products);
     // iterate through every product on this sales operation
     foreach ($products as $product) {
         $newDetail = SalesDetailQuery::create()->findOneById($product->id);
         // check whether current detail iteration is brand new or just updating the old one
         if (!$newDetail) {
             $isNew = true;
             $newDetail = new SalesDetail();
         } else {
             $isNew = false;
             $oldDetail = $newDetail->copy();
         }
         $newDetail->setSalesId($sales->getId())->setType($product->type)->setStockId($product->stock_id)->setAmount($product->amount)->setUnitPrice($product->unit_price)->setDiscount($product->discount)->setTotalPrice($product->total_price)->setBuy($product->buy)->setSellPublic($product->sell_public)->setSellDistributor($product->sell_distributor)->setSellMisc($product->sell_misc)->setStatus('Active')->save($con);
         // make stock dance ^_^
         if ($isNew) {
             $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
             if ($stock->getUnlimited() == false) {
                 $stock->setAmount($stock->getAmount() - $newDetail->getAmount())->save($con);
             }
         } else {
             // check whether updated detail stock is the same old one or not
             if ($newDetail->getStockId() == $oldDetail->getStockId()) {
                 // and if actually the same, then set stock amount like this
                 // amount = currentAmount + oldTransAmount - newTransAmount
                 $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
                 if ($stock->getUnlimited() == false) {
                     $stock->setAmount($stock->getAmount() + $oldDetail->getAmount() - $newDetail->getAmount())->save($con);
                 }
             } else {
                 // but if two stocks is not the same,
                 // then give back oldTransAmount to old-stock, and take newTransAmount from new-stock
                 $stock = StockQuery::create()->findOneById($oldDetail->getStockId(), $con);
                 if ($stock->getUnlimited() == false) {
                     $stock->setAmount($stock->getAmount() + $oldDetail->getAmount())->save($con);
                 }
                 $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
                 if ($stock->getUnlimited() == false) {
                     $stock->setAmount($stock->getAmount() - $newDetail->getAmount())->save($con);
                 }
             }
         }
     }
     // if there are any sales detail removed then make sure the stocks get what it deserve... 'gimme amount'
     $removeds = SalesDetailQuery::create()->filterById($params->removed_id)->find($con);
     foreach ($removeds as $removed) {
         $stock = StockQuery::create()->findOneById($removed->getStockId(), $con);
         if ($stock->getUnlimited() == false) {
             $stock->setAmount($stock->getAmount() + $removed->getAmount())->save($con);
         }
         $removed->setStatus('Deleted')->save($con);
     }
     $logData['params'] = $params;
     // log history
     $salesHistory = new SalesHistory();
     $salesHistory->setUserId($currentUser->id)->setSalesId($params->id)->setTime(time())->setOperation('update')->setData(json_encode($logData))->save($con);
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
Пример #7
0
 /**
  * Performs an INSERT on the database, given a Credit or Criteria object.
  *
  * @param mixed               $criteria Criteria or Credit object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(CreditTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Credit object
     }
     if ($criteria->containsKey(CreditTableMap::COL_ID) && $criteria->keyContainsValue(CreditTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . CreditTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = CreditQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }
Пример #8
0
 /**
  * Returns the number of related Credit objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Credit objects.
  * @throws PropelException
  */
 public function countCredits(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collCreditsPartial && !$this->isNew();
     if (null === $this->collCredits || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collCredits) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getCredits());
         }
         $query = ChildCreditQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterBySales($this)->count($con);
     }
     return count($this->collCredits);
 }
Пример #9
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Credit::setDeleted()
  * @see Credit::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(CreditTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildCreditQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }
Пример #10
0
 /**
  * Get the associated ChildCredit object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildCredit The associated ChildCredit object.
  * @throws PropelException
  */
 public function getCredit(ConnectionInterface $con = null)
 {
     if ($this->aCredit === null && ($this->credit_id !== "" && $this->credit_id !== null)) {
         $this->aCredit = ChildCreditQuery::create()->findPk($this->credit_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aCredit->addPayments($this);
            */
     }
     return $this->aCredit;
 }