Exemplo n.º 1
0
 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();
                 }
             }
         }
     }
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $model1 = $this->loadModel($id);
     $model1->balance = 0;
     $creditModel = CustomersCredit::model()->find(array('condition' => 'credited_from=:id', 'params' => array(':id' => $id)));
     if (isset($creditModel)) {
         $creditModel->credit_assigned = 0;
         $creditModel->save();
     }
     $model1->save();
     $this->redirect(array('AutomatedTransaction', 'id' => $id, 'mode' => 'delete'));
     $model1->delete();
     //$this->redirect(array('index'));
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     //if(!isset($_GET['ajax']))
     //  $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
 }
<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;
foreach (CustomersCredit::model()->findAll(array('order' => 'credited_date', 'condition' => 'customer_id=:customer', 'params' => array(':customer' => $id))) as $receipt) {
    ?>
        <tr>
            <td>
            </td>
            <td>

            </td>
            <td>
                <?php 
    echo $receipt->credited_date;
    ?>
            </td>
            <td>

            </td>
            <td>
Exemplo n.º 4
0
                <?php 
    echo '-' . $receipt->amount;
    ?>
            </td>
            <td>
                <?php 
    $balance -= $receipt->amount;
    echo $balance;
    ?>
            </td>
        </tr>
    <?php 
}
?>
    <?php 
foreach (CustomersCredit::model()->findAll(array('condition' => 'credited_from=:invoice', 'params' => array(':invoice' => $id))) as $receipt) {
    ?>
        <tr>
            <td>
            </td>
            <td>

            </td>
            <td>
                <?php 
    echo $receipt->credited_date;
    ?>
            </td>
            <td>

            </td>
Exemplo n.º 5
0
 public static function GetCreditfor($salesInvoice, $remainingCredit)
 {
     foreach (CustomersCredit::model()->findAll(array('condition' => 'customer_id=:customer', 'params' => array(':customer' => $salesInvoice->customer_id))) as $indModel) {
         $creditRemained = $indModel->amount - $indModel->credit_assigned;
         if ($remainingCredit <= 0) {
             break;
         } else {
             if ($creditRemained > $remainingCredit) {
                 $creditBorrowed = $remainingCredit;
             } else {
                 $creditBorrowed = $creditRemained;
             }
             $transaction = new AutomatedTransactionCustomers();
             $transaction->received_date = $indModel->credited_date;
             $transaction->from_sales_invoice_id = $indModel->credited_from;
             $transaction->to_sales_invoice_id = $salesInvoice->id;
             $transaction->amount = $creditBorrowed;
             $transaction->customer_id = $salesInvoice->customer_id;
             $indModel->credit_assigned += $creditBorrowed;
             $salesInvoice->credited += $creditBorrowed;
             $salesInvoice->save();
             $transaction->save();
             $indModel->save();
             $remainingCredit -= $creditBorrowed;
         }
     }
 }
Exemplo n.º 6
0
</th>
                    <th><?php 
    echo $total_credit_payables;
    ?>
</th>
                </tr>
                <tr><td colspan="10"></td></tr>
            <!----------------------------------------------account payables end-------------------------------->
            <!-----------------------------customer credits start------------------------------------------------->
                <tr>
                    <th colspan="10">Customers Credit</th>
                </tr>
                <?php 
    $total_debit_customerCredit = 0;
    $total_credit_customerCredit = 0;
    foreach (CustomersCredit::model()->findAll(array('order' => 'credited_date', 'condition' => 'credited_date>=:start_date AND credited_date<=:end_date', 'params' => array(':start_date' => $model->from_date, ':end_date' => $model->to_date))) as $creditRow) {
        ?>
                    <tr>
                        <td colspan="8"><?php 
        echo $creditRow->credited_date . '- ' . $creditRow->customer->customerName . '-OverPayment on SalesInvoice #' . $salesInv->id . ' transferred to customer credit';
        ?>
</td>
                        <td></td>
                        <td><?php 
        $total_credit_customerCredit += $creditRow->amount;
        echo $creditRow->amount;
        ?>
                        </td>

                    </tr>
Exemplo n.º 7
0
    ?>
            </td>
            <td>
                <?php 
    echo $model->BillingAddress;
    ?>
            </td>
            <td>
                <?php 
    echo CHtml::link(sizeof($model->salesInvoices), $this->createAbsoluteUrl('SalesInvoices/index', array('customer' => $model->id)));
    ?>
            </td>

            <td>
                <?php 
    $customerCredits = CustomersCredit::model()->findAll(array('condition' => 'customer_id=:customer', 'params' => array(':customer' => $model->id)));
    $credits = 0;
    foreach ($customerCredits as $customerCredit) {
        $credits += $customerCredit->amount - $customerCredit->credit_assigned;
    }
    if ($credits < 0) {
        echo '-';
    } else {
        echo CHtml::link($credits, $this->createAbsoluteUrl('customers/viewTransactionCreditType', array('id' => $model->id)));
    }
    ?>
            </td>

            <td>
                <?php 
    $Invoices = $model->salesInvoices;