slipDO.setSeed(seedDO);
List<BussinessTransactionDO> transactionObjects = new LinkedList<BussinessTransactionDO>();
//Debit from buyer transaction.
BussinessTransactionDO buyerTransactionDO = new BussinessTransactionDO();
buyerTransactionDO.setDatetime(currentTime);
buyerTransactionDO.setAmount(purchaseSlip.getGrossTotal());
buyerTransactionDO.setAccount(buyerAccountDO);
buyerTransactionDO.setSlip(slipDO);
buyerTransactionDO.setTransFlow(Constants.DEBIT); // flow is debit
buyerTransactionDO.setPaymentMode(Constants.PAYMENT_MODE_CASH);
buyerTransactionDO.setDescription("Debited from firm to indicate that buyer has to pay to firm");
transactionObjects.add(buyerTransactionDO);
//Credit to supplier transaction.
BussinessTransactionDO supplierTransactionDO = new BussinessTransactionDO();
supplierTransactionDO.setDatetime(currentTime);
supplierTransactionDO.setAmount(purchaseSlip.getNetTotal());
supplierTransactionDO.setAccount(supplierAccountDO);
supplierTransactionDO.setSlip(slipDO);
supplierTransactionDO.setTransFlow(Constants.CREDIT);
supplierTransactionDO.setPaymentMode(Constants.PAYMENT_MODE_CASH);
supplierTransactionDO.setDescription("Credited to firm to indicate that firm has to pay to supplier");
transactionObjects.add(supplierTransactionDO);
//Credit to HAMALI transaction.
BussinessTransactionDO hamaliTransactionDO = new BussinessTransactionDO();
hamaliTransactionDO.setDatetime(currentTime);
hamaliTransactionDO.setAmount(purchaseSlip.getTotalHamali());
hamaliTransactionDO.setAccount(hamaliAccountDO);
hamaliTransactionDO.setSlip(slipDO);
hamaliTransactionDO.setTransFlow(Constants.CREDIT);
hamaliTransactionDO.setPaymentMode(Constants.PAYMENT_MODE_CASH);
hamaliTransactionDO.setDescription("Credited to firm to indicate that firm has to pay to Hamali");
transactionObjects.add(hamaliTransactionDO);
//Credit to CC transaction.
BussinessTransactionDO ccTransactionDO = new BussinessTransactionDO();
ccTransactionDO.setDatetime(currentTime);
ccTransactionDO.setAmount(purchaseSlip.getTotalCc());
ccTransactionDO.setAccount(ccAccountDO);
ccTransactionDO.setSlip(slipDO);
ccTransactionDO.setTransFlow(Constants.CREDIT);
ccTransactionDO.setPaymentMode(Constants.PAYMENT_MODE_CASH);
ccTransactionDO.setDescription("Credited to firm to indicate that firm has to pay to CC account");
transactionObjects.add(ccTransactionDO);
//Credit to MF transaction.
BussinessTransactionDO mfTransactionDO = new BussinessTransactionDO();
mfTransactionDO.setDatetime(currentTime);
mfTransactionDO.setAmount(purchaseSlip.getTotalMf());
mfTransactionDO.setAccount(mfAccountDO);
mfTransactionDO.setSlip(slipDO);
mfTransactionDO.setTransFlow(Constants.CREDIT);
mfTransactionDO.setPaymentMode(Constants.PAYMENT_MODE_CASH);
mfTransactionDO.setDescription("Credited to firm to indicate that firm has to pay to MF account");
transactionObjects.add(mfTransactionDO);
//Insert payment transaction if purchase status is not pending.
if(!purchaseSlip.getStatus().equals(Constants.BILL_STATUS_PENDING)){
//payment transaction.
BussinessTransactionDO payment = new BussinessTransactionDO();
payment.setDatetime(currentTime);
payment.setAmount(purchaseSlip.getPaymentAmount());
payment.setAccount(supplierAccountDO);
payment.setSlip(slipDO);
payment.setTransFlow(Constants.DEBIT);
if(purchaseSlip.getPaymentMode().equals(Constants.PAYMENT_MODE_CASH)){
payment.setPaymentMode(Constants.PAYMENT_MODE_CASH);
}else{
PaymentDetailsDO paymentDetails = new PaymentDetailsDO();
paymentDetails.setDatetime(currentTime);
paymentDetails.setAmount(purchaseSlip.getPaymentAmount());
paymentDetails.setCheckNumber(purchaseSlip.getCheckNumber());
paymentDetails.setBankName(purchaseSlip.getBankName());
paymentDetails.setBranchName(purchaseSlip.getBranchName());
paymentDetails.setBusinessTransaction(payment);
paymentDetails.setDescription("Firm has paid this amount towards this bill");
payment.setPaymentMode(Constants.PAYMENT_MODE_CHECK);
payment.setPaymentDetails(paymentDetails);
}
payment.setDescription("Firm has paid this amount to supplier");
transactionObjects.add(payment);
}
transactionsDAO.saveBusinessTransactions(transactionObjects);