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();
                 }
             }
         }
     }
 }
 public 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;
         }
     }
 }
                <?php 
    echo $receipt->amount;
    ?>
            </td>
            <td>
                <?php 
    $balance += $receipt->amount;
    echo $balance;
    ?>
            </td>
        </tr>
    <?php 
}
?>
    <?php 
foreach (AutomatedTransactionCustomers::model()->findAll(array('order' => 'received_date', 'condition' => 'customer_id=:customer', 'params' => array(':customer' => $id))) as $receipt) {
    ?>
        <tr>
            <td>
            </td>
            <td>

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

            </td>
    }
    ?>
</span>
                    <?php 
    if ($balance >= 0) {
        echo $balance;
    }
    ?>
                </td>
            </tr>

        <?php 
}
?>
    <?php 
foreach (AutomatedTransactionCustomers::model()->findAll(array('condition' => 'to_sales_invoice_id=:invoice', 'params' => array(':invoice' => $id))) as $receipt) {
    ?>
        <tr>
            <td>
            </td>
            <td>

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

            </td>
Beispiel #5
0
                        <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>

                <?php 
    }
    foreach (AutomatedTransactionCustomers::model()->findAll(array('condition' => 'received_date>=:start_date AND received_date<=:end_date', 'params' => array(':start_date' => $model->from_date, ':end_date' => $model->to_date))) as $transac) {
        ?>
                    <tr>

                        <td colspan="8"><?php 
        echo $transac->received_date . '- ' . $transac->customer->customerName . '-Automatic credit allocation to sales invoice #' . $transac->to_sales_invoice_id;
        ?>
</td>

                        <td><?php 
        $total_debit_customerCredit += $transac->amount;
        echo $transac->amount;
        ?>
                        </td>
                        <td></td>
                    </tr>