public function AutomatedExecutionHandler() { AutomatedTransactionCustomers::model()->deleteAll(); $modelCredits = CustomersCredit::model()->findAll(array('order' => 'credited_date')); foreach (SalesInvoices::model()->findAll() as $indSalesInv) { $indSalesInv->credited = 0; $indSalesInv->save(); } foreach ($modelCredits as $indCredits) { $modelInvoices = SalesInvoices::model()->findAll(array('condition' => 'customer_id=:customer_id', 'params' => array(':customer_id' => $indCredits->customer_id))); $temp_ind_credit = $indCredits->amount; while ($temp_ind_credit > 0) { foreach ($modelInvoices as $indInvoices) { $actualBalance = $indInvoices->balance - $indInvoices->credited; if ($actualBalance > 0) { $transactionModel = new AutomatedTransactionCustomers(); if ($temp_ind_credit >= $actualBalance) { $indInvoices->credited += $actualBalance; $temp_ind_credit -= $actualBalance; $amount = $actualBalance; } else { $indInvoices->credited += $temp_ind_credit; $temp_ind_credit = 0; $amount = $temp_ind_credit; } $indInvoices->save(); $transactionModel->received_date = $indCredits->credited_date; $transactionModel->customer_id = $indCredits->customer_id; $transactionModel->amount = $amount; $transactionModel->from_sales_invoice_id = $indCredits->credited_from; $transactionModel->to_sales_invoice_id = $indInvoices->id; $transactionModel->save(); } } } } }
/** * 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 SalesInvoices the loaded model * @throws CHttpException */ public function loadModel($id) { $model = SalesInvoices::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<table class="table table-bordered"> <tr> <th>Edit</th> <th>View</th> <th>Date</th> <th>Transacation</th> <th>#</th> <th>Description</th> <th>Contact</th> <th>Amount</th> <th>Balance</th> </tr> <tr> <?php $balance = 0; $SalesInvoice = SalesInvoices::model()->findByPk($id); ?> <td><?php echo CHtml::link('<button class="btn btn-default btn-sm"><span class="btn-label-style">Edit</span></button>', $this->createAbsoluteUrl('salesInvoices/update', array('id' => $id))); ?> </td> <td><?php echo CHtml::link('<button class="btn btn-default btn-sm"><span class="btn-label-style">View</span></button>', $this->createAbsoluteUrl('salesInvoices/view', array('id' => $id))); ?> </td> <td> <?php echo $SalesInvoice->issue_date; ?> </td> <td>
<table class="table table-bordered"> <tr> <th>Edit</th> <th>View</th> <th>Date</th> <th>Transacation</th> <th>#</th> <th>Description</th> <th>Contact</th> <th>Amount</th> <th>Balance</th> </tr> <?php $balance = 0; $SalesInvoices = SalesInvoices::model()->findAll(array('order' => 'issue_date', 'condition' => 'customer_id=:customer', 'params' => array(':customer' => $id))); foreach ($SalesInvoices as $SalesInvoice) { ?> <tr> <td><?php echo CHtml::link('<button class="btn btn-default btn-sm"><span class="btn-label-style">Edit</span></button>', $this->createAbsoluteUrl('salesInvoices/update', array('id' => $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('salesInvoices/view', array('id' => $SalesInvoice->id))); ?> </td> <td> <?php echo $SalesInvoice->issue_date; ?> </td>
<h2>Update MoneyReceived</h2> <div style="border: 1px inset gold;padding: 3%;"> <span><b>Customer: </b><?php echo Customers::model()->findByPk(SalesInvoices::model()->findByPk($id)->customer_id)->customerName; ?> </span> <br> <br> <span><b>Sales Invoice: </b><?php echo $id; ?> </span> <br> <br> <?php $this->renderPartial('_form', array('model' => $model, 'id' => $id)); ?> </div>
public static function TransferringCredit($indvCredited) { $creditRemainingOfThisModel = $indvCredited->amount - $indvCredited->credit_assigned; foreach (SalesInvoices::model()->findAll(array('condition' => 'customer_id=:customer', 'params' => array(':customer' => $indvCredited->customer_id))) as $indvSalesInvoice) { if ($creditRemainingOfThisModel > 0) { //echo $creditRemainingOfThisModel; $amountToGetBalanced = $indvSalesInvoice->balance - $indvSalesInvoice->credited; //echo $amountToGetBalanced; if ($amountToGetBalanced > 0) { if ($creditRemainingOfThisModel > $amountToGetBalanced) { $amountCredited = $amountToGetBalanced; } else { $amountCredited = $creditRemainingOfThisModel; } $indvSalesInvoice->credited += $amountCredited; $indvCredited->credit_assigned += $amountCredited; $creditRemainingOfThisModel -= $amountCredited; $transaction = new AutomatedTransactionCustomers(); $transaction->received_date = $indvCredited->credited_date; $transaction->customer_id = $indvCredited->customer_id; $transaction->from_sales_invoice_id = $indvCredited->credited_from; $transaction->to_sales_invoice_id = $indvSalesInvoice->id; $transaction->amount = $amountCredited; $indvSalesInvoice->save(); $indvCredited->save(); $transaction->save(); } } else { } } }
</td> <td><?php $total_debit_invoice += $purchasesInfo->total_amount; echo $purchasesInfo->total_amount; ?> </td> <td></td> </tr> <?php } } ?> <?php $total_credit_invoice = 0; foreach (SalesInvoices::model()->findAll(array('order' => 'issue_date', 'condition' => 'issue_date>=:start_date AND issue_date<=:end_date', 'params' => array(':start_date' => $model->from_date, ':end_date' => $model->to_date))) as $salesInv) { foreach ($salesInv->salesInfos as $salesInfo) { ?> <tr> <td colspan="8"><?php echo $salesInv->issue_date . '- ' . $salesInv->customer->customerName . '-SalesInvoice #' . $salesInv->id . '- ' . $salesInfo->item->item_name; ?> </td> <td></td> <td> <?php $unit_cost_price = 0; $total_cost = 0; $qty = 0; foreach (PurchasesInvoices::model()->findAll(array('condition' => 'issue_date<=:sales_inv_issue_date', 'params' => array(':sales_inv_issue_date' => $salesInv->issue_date))) as $purchasesInv) { foreach ($purchasesInv->purchasesInfos as $purchasesInfo) {