Ejemplo n.º 1
0
                <?php 
    echo $receipt->amount;
    ?>
            </td>
            <td>
                <?php 
    $balance += $receipt->amount;
    echo $balance;
    ?>
            </td>
        </tr>
    <?php 
}
?>
    <?php 
foreach (AutomatedTransactionSuppliers::model()->findAll(array('order' => 'paid_date', 'condition' => 'supplier_id=:supplier', 'params' => array(':supplier' => $id))) as $receipt) {
    ?>
        <tr>
            <td>
            </td>
            <td>

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

            </td>
Ejemplo n.º 2
0
                <tr>
                    <td colspan="8"><?php 
        echo $creditRow->credited_date . '- ' . $creditRow->supplier->supplierName . '-OverPayment on purchases invoice #' . $creditRow->credited_from . ' transferred to customer credit';
        ?>
</td>

                    <td><?php 
        $total_debit_suppliersCredit += $creditRow->amount;
        echo $creditRow->amount;
        ?>
                    </td>
                    <td></td>
                </tr>
                <?php 
    }
    foreach (AutomatedTransactionSuppliers::model()->findAll(array('condition' => 'paid_date>=:start_date AND paid_date<=:end_date', 'params' => array(':start_date' => $model->from_date, ':end_date' => $model->to_date))) as $transac) {
        ?>
                    <tr>

                        <td colspan="8"><?php 
        echo $transac->paid_date . '- ' . $transac->supplier->supplierName . '-Automatic credit allocation to purchases invoice #' . $transac->to_purchases_invoice_id;
        ?>
</td>

                        <td><?php 
        $total_debit_suppliersCredit += $transac->amount;
        echo $transac->amount;
        ?>
                        </td>
                        <td></td>
                    </tr>
Ejemplo n.º 3
0
 public function actionAutomatedTransaction($id, $mode)
 {
     $purchasesInv = PurchasesInvoices::model()->findByPk($id);
     $suppliersCredit = SuppliersCredit::model()->find(array('condition' => 'credited_from=:invoice', 'params' => array(':invoice' => $id)));
     $remainingCredit = $purchasesInv->credited - $purchasesInv->balance;
     if ($remainingCredit > 0) {
         $purchasesInv->credited = $purchasesInv->balance;
         $modelsCreditedFrom = AutomatedTransactionSuppliers::model()->findAll(array('condition' => 'to_purchases_invoice_id=:invoice_id', 'params' => array(':invoice_id' => $purchasesInv->id)));
         $creditedModels = array();
         foreach ($modelsCreditedFrom as $indCredited) {
             $i = 0;
             $creditAssigned = $indCredited->amount;
             $creditedModel = SuppliersCredit::model()->find(array('condition' => 'credited_from=:invoice', 'params' => array(':invoice' => $indCredited->from_purchases_invoice_id)));
             if ($remainingCredit >= $creditAssigned) {
                 $indCredited->delete();
                 $creditedModel->credit_assigned -= $creditAssigned;
                 $creditedModel->save();
                 $remainingCredit -= $creditAssigned;
                 $creditedModels[$i] = $creditedModel;
                 $i++;
             } else {
                 $indCredited->amount -= $remainingCredit;
                 $creditedModel->credit_assigned -= $remainingCredit;
                 $creditedModel->save();
                 $indCredited->save();
                 $creditedModels[$i] = $creditedModel;
                 break;
             }
         }
         $purchasesInv->save();
         foreach ($creditedModels as $indvCredited) {
             $this->TransferringCredit($indvCredited);
         }
     } else {
         if ($remainingCredit < 0) {
             $remainingCredit = -1 * $remainingCredit;
             $this->GetCreditfor($purchasesInv, $remainingCredit);
         }
     }
     if (isset($suppliersCredit)) {
         $creditRemainingOfThisModel = $suppliersCredit->amount - $suppliersCredit->credit_assigned;
         if ($creditRemainingOfThisModel > 0) {
             $this->TransferringCredit($suppliersCredit);
         } else {
             if ($creditRemainingOfThisModel < 0) {
                 $overAssignedCredit = -1 * $creditRemainingOfThisModel;
                 $creditTakers = AutomatedTransactionSuppliers::model()->findAll(array('condition' => 'from_purchases_invoice_id=:invoice', 'params' => array(':invoice' => $suppliersCredit->credited_from)));
                 $creditTakerInvoices = array();
                 $i = 0;
                 foreach ($creditTakers as $creditTaker) {
                     if ($overAssignedCredit > 0) {
                         $creditTakerInvoice = PurchasesInvoices::model()->findByPk($creditTaker->to_purchases_invoice_id);
                         if ($creditTaker->amount <= $overAssignedCredit) {
                             $creditDeducted = $creditTaker->amount;
                             $creditTaker->delete();
                         } else {
                             $creditDeducted = $overAssignedCredit;
                             $creditTaker->amount -= $creditDeducted;
                             $creditTaker->save();
                         }
                         $creditTakerInvoice->credited -= $creditDeducted;
                         $creditTakerInvoice->save();
                         $overAssignedCredit -= $creditDeducted;
                         $creditTakerInvoices[$i] = $creditTakerInvoice;
                         $i++;
                     } else {
                     }
                 }
                 foreach ($creditTakerInvoices as $creditTakerInv) {
                     $creditToPay = $creditTakerInv->balance - $creditTakerInv->credited;
                     $this->GetCreditfor($creditTakerInv, $creditToPay);
                 }
             }
             if ($suppliersCredit->amount == 0) {
                 $suppliersCredit->delete();
             } else {
                 $suppliersCredit->credit_assigned = $suppliersCredit->amount;
                 $suppliersCredit->save();
             }
         }
     }
     if ($mode == 'delete') {
         $purchasesInv->delete();
         $this->redirect(array('purchasesInvoices/index'));
     }
     $this->redirect(array('purchasesInvoices/view', 'id' => $id));
 }
Ejemplo n.º 4
0
    }
    ?>
</span>
                    <?php 
    if ($balance >= 0) {
        echo $balance;
    }
    ?>
                </td>
            </tr>

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

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

            </td>