예제 #1
0
 public function beforeDelete()
 {
     $item = InventoryItems::model()->findByPk($this->item_id);
     $item->qty += $this->qty;
     $item->save();
     return parent::beforeDelete();
 }
 /**
  * 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));
 }
예제 #3
0
                <td class="left-bordered bottom-bordered">
                    <b>Amount</b>
                </td>
            </tr>
            <?php 
foreach ($modelSalesInfos as $serialNum => $indModel) {
    ?>
                <tr>
                    <td>
                        <?php 
    echo $serialNum;
    ?>
                    </td>
                    <td class="left-bordered">
                        <?php 
    echo InventoryItems::model()->findByPk($indModel->item_id)->item_name;
    ?>
                    </td>
                    <td class="left-bordered">
                        <?php 
    echo $indModel->unit_price;
    ?>
                    </td>
                    <td class="left-bordered">
                        <?php 
    echo $indModel->qty;
    ?>
                    </td>
                    <td class="left-bordered">
                        <?php 
    echo $indModel->total_amount;
예제 #4
0
    ?>
            </div>
           <?php 
    echo $form->error($model2, 'total_amount');
    ?>
        </div>

    <?php 
} else {
    ?>
        <div class="row row1">
            <?php 
    echo $form->labelEx($model2, '');
    ?>
            <?php 
    $this->widget('bootstrap.widgets.select2.ESelect2', array('model' => $model2, 'attribute' => "[{$sts}]item_id", 'data' => CHtml::listData(InventoryItems::model()->findAll(), 'id', 'item_name'), 'htmlOptions' => array('class' => 'form-control')));
    ?>
            <?php 
    echo $form->error($model2, 'item_id');
    ?>
        </div>

        <div class="row row2">
            <?php 
    echo $form->labelEx($model2, '');
    ?>
            <div class="input-prepend">
                <span class="add-on" style="margin-top: 3px;">Rs.</span>
                <?php 
    echo $form->textField($model2, "[{$sts}]unit_price", array('class' => $sts));
    ?>
 /**
  * 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 InventoryItems the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = InventoryItems::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }