示例#1
0
            </td>
            <td>
                <?php 
    echo $PurchasesInfo->qty;
    ?>
            </td>
            <td>
                <?php 
    $balance += $PurchasesInfo->qty;
    echo $balance;
    ?>
            </td>
                </tr>
        <?php 
}
$SalesInfos = SalesInfo::model()->findAll(array('condition' => 'item_id=:item', 'params' => array(':item' => $id)));
foreach ($SalesInfos as $SalesInfo) {
    ?>
        <tr>
            <td><?php 
    echo CHtml::link('<button class="btn btn-default btn-sm"><span class="btn-label-style">Edit</span></button>', $this->createAbsoluteUrl('salesInfos/update', array('id' => $SalesInfo->salesInvoice->id)));
    ?>
            </td>
            <td><?php 
    echo CHtml::link('<button class="btn btn-default btn-sm"><span class="btn-label-style">View</span></button>', $this->createAbsoluteUrl('SalesInfos/view', array('id' => $SalesInfo->salesInvoice->id)));
    ?>
            </td>
            <td>
                <?php 
    echo $SalesInfo->salesInvoice->issue_date;
    ?>
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $i = 0;
     $model1 = $this->loadModel($id);
     $model2 = $model1->salesInfos;
     $receivedModel = $this->loadReceivedModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['SalesInvoices'])) {
         $model1->attributes = $_POST['SalesInvoices'];
         $model1->save();
         $sales_invoice_id = $model1->id;
         if (isset($_POST['SalesInfo'])) {
             $item_qty = array();
             foreach ($model2 as $cnt => $indModel) {
                 $item_qty[$cnt] = $indModel->qty;
                 $indModel->delete();
             }
             while ($i <= $_SESSION['sts']) {
                 if (isset($_POST['SalesInfo'][$i])) {
                     $indModel = new SalesInfo();
                     $indModel->attributes = $_POST['SalesInfo'][$i];
                     $indModel->sales_invoice_id = $sales_invoice_id;
                     $indModel->save();
                     $item = InventoryItems::model()->findByPk($indModel->item_id);
                     $item->qty -= $indModel->qty - $item_qty[$i];
                     $item->save();
                 }
                 $i++;
             }
             //$model2->save();
         }
         if (isset($_POST['MoneyReceived'])) {
             $receivedModel->attributes = $_POST['MoneyReceived'];
             $receivedModel->save();
             $total_received = 0;
             foreach (MoneyReceived::model()->findAll(array('condition' => 'sales_invoice_id=:invoice', 'params' => array(':invoice' => $id))) as $receipts) {
                 $total_received += $receipts->amount;
             }
             $tempBalance = $model1->total_amount - $total_received;
             $creditRow = CustomersCredit::model()->find(array('condition' => 'credited_from=:invoice', 'params' => array(':invoice' => $id)));
             if ($tempBalance >= 0) {
                 $model1->balance = $tempBalance;
                 if (isset($creditRow)) {
                     $creditRow->amount = 0;
                     $creditRow->save();
                 }
             } else {
                 $model1->balance = 0;
                 if (!isset($creditRow)) {
                     $creditRow = new CustomersCredit();
                     $creditRow->credited_from = $id;
                     $creditRow->customer_id = $model1->customer_id;
                 }
                 $creditRow->amount = -1 * $tempBalance;
                 $creditRow->credited_date = $model1->issue_date;
                 $creditRow->customer_id = $model1->customer_id;
                 $creditRow->save();
             }
             $model1->save();
         }
         $this->redirect(array('AutomatedTransaction', 'id' => $model1->id, 'mode' => ''));
         //$this->redirect(array('view','id'=>$model1->id));
     }
     $this->render('update', array('model1' => $model1, 'model2' => $model2, 'receivedModel' => $receivedModel));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return SalesInfo the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SalesInfo::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }