コード例 #1
0
ファイル: Reports.php プロジェクト: iHunt101/POS-ws-server
 private static function getSaledProduct($date, $con)
 {
     $saledProducts = SalesDetailQuery::create()->filterByStatus('Active')->useStockQuery()->leftJoin('Product')->leftJoin('Unit')->withColumn('Product.Name', 'product_name')->withColumn('Unit.Name', 'unit_name')->endUse()->useSalesQuery()->filterByStatus('Active')->filterByDate(array('min' => $date->start, 'max' => $date->until))->endUse()->withColumn('SUM(SalesDetail.Amount)', 'saled_amount')->withColumn('SUM(SalesDetail.TotalPrice)', 'saled_total')->select(array('stock_id', 'product_name', 'unit_name', 'saled_amount', 'saled_total'))->groupBy('SalesDetail.StockId')->orderBy('saled_amount', 'DESC')->find($con);
     $data = [];
     foreach ($saledProducts as $saledProduct) {
         $data[] = $saledProduct;
     }
     $results['success'] = true;
     $results['data'] = $data;
     return $results;
 }
コード例 #2
0
ファイル: nota-sales.php プロジェクト: AlvaCorp/POS-2
    <link rel="stylesheet" type="text/css" href="print.css">
</head>
<script>
    setTimeout(function(){
        window.print();
        window.close();
    }, 10)
</script>
<body>
<?php 
$sales = SalesQuery::create()->leftJoin('SecondParty')->leftJoin('Cashier')->filterByStatus('Active')->filterById($id)->select(array('id', 'date', 'total_price', 'paid', 'note'))->withColumn('SecondParty.Name', 'second_party_name')->withColumn('Cashier.Id', 'cashier_id')->withColumn('Cashier.Name', 'cashier_name')->findOne($con);
if (!$sales) {
    throw die('Data tidak ditemukan.');
}
$sales = (object) $sales;
$salesDetails = SalesDetailQuery::create()->filterBySalesId($sales->id)->filterByStatus('Active')->select(array('amount', 'unit_price', 'discount', 'total_price'))->useStockQuery()->leftJoin('Product')->leftJoin('Unit')->withColumn('Product.Name', 'product_name')->withColumn('Unit.Name', 'unit_name')->endUse()->find($con);
?>

<div style="font-weight: bold; font-size: 15px; text-align: center;">
    <?php 
echo $info->client_name;
?>
</div>
<div style="text-align: center;"><?php 
echo $info->client_address;
?>
. Telp <?php 
echo $info->client_phone;
?>
</div>
コード例 #3
0
ファイル: SalesDetailQuery.php プロジェクト: AlvaCorp/POS-2
 /**
  * Returns a new ChildSalesDetailQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildSalesDetailQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildSalesDetailQuery) {
         return $criteria;
     }
     $query = new ChildSalesDetailQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
コード例 #4
0
ファイル: Stock.php プロジェクト: AlvaCorp/POS-2
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Stock is new, it will return
  * an empty collection; or if this Stock has previously
  * been saved, it will retrieve related Saless from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Stock.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return ObjectCollection|ChildSalesDetail[] List of ChildSalesDetail objects
  */
 public function getSalessJoinSales(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildSalesDetailQuery::create(null, $criteria);
     $query->joinWith('Sales', $joinBehavior);
     return $this->getSaless($query, $con);
 }
コード例 #5
0
 /**
  * Performs an INSERT on the database, given a SalesDetail or Criteria object.
  *
  * @param mixed               $criteria Criteria or SalesDetail 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(SalesDetailTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from SalesDetail object
     }
     if ($criteria->containsKey(SalesDetailTableMap::COL_ID) && $criteria->keyContainsValue(SalesDetailTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . SalesDetailTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = SalesDetailQuery::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);
     });
 }
コード例 #6
0
ファイル: Sale.php プロジェクト: iHunt101/POS-ws-server
 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
ファイル: SalesDetail.php プロジェクト: AlvaCorp/POS-2
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see SalesDetail::setDeleted()
  * @see SalesDetail::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(SalesDetailTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildSalesDetailQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }