Beispiel #1
0
        public bool SendLodgementReimbursementMail(shop shop, mail mail, master_transaction tran)
        {
            try
            {
                admin_user user = new CRUD.admin_users_crud().find_admin_user_By_ID(shop.agent.Value);
                string     body = mail.content;
                if (user != null && user.email != "" && user.email != string.Empty && user.email != null)
                {
                    string accountName = ((user.firstname != null) ? user.firstname.ToUpperInvariant() : "") + " " + ((user.middlename != null) ? user.middlename.ToUpperInvariant() : "") + " " + ((user.lastname != null) ? user.lastname.ToUpperInvariant() : "");
                    string balance     = "";
                    if (shop.master_balance_sheets != null && shop.master_balance_sheets.Count > 0)
                    {
                        balance = tran.amount.ToString();
                    }

                    body = body.Replace("{shop_code}", shop.shop_code);
                    body = body.Replace("{account_name}", (accountName != null) ? accountName : "UNAVAILABLE");
                    body = body.Replace("{amount}", balance);
                    body = body.Replace("{curr_debt_bal}", tran.balance_after.ToString());
                    body = body.Replace("{bank_acct}", getbankaccounts());

                    SendBulkMail(user.email, mail.name, body);
                    return(true);
                }
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public bool SaveLapsePaymentTransaction(master_transaction newmastertransaction, master_balance_sheet masterbalance)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    newmastertransaction.app_id = Application().app_id;

                    db.master_transactions.InsertOnSubmit(newmastertransaction);

                    master_balance_sheet prev_master_balance_sheet = db.master_balance_sheets.SingleOrDefault(a => a.id == masterbalance.id);

                    prev_master_balance_sheet.credit_balance = masterbalance.credit_balance;
                    prev_master_balance_sheet.netbalance     = masterbalance.netbalance;
                    prev_master_balance_sheet.online_credit  = masterbalance.online_credit;
                    prev_master_balance_sheet.sales_balance  = masterbalance.sales_balance;


                    db.SubmitChanges();

                    scope.Complete();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #3
0
        private master_transaction initializeDailySalesTransaction(string transcode, decimal amount)
        {
            transaction_category tranct = trancategory.SingleOrDefault(a => a.code == transcode);
            master_transaction   trans  = new master_transaction();

            trans.amount          = master_daily_sale.sales;
            trans.shop            = master_daily_sale.shop;
            trans.trans_timestamp = DateTime.Now;
            trans.details         = tranct.name + " For " + ((DateTime)master_daily_sale.date).ToShortDateString();
            trans.description     = tranct.name + " For " + ((DateTime)master_daily_sale.date).ToShortDateString();
            application app = new application
            {
                app_id = Guid.NewGuid().ToString()
            };

            trans.app_id = app.app_id;
            // master_balance_sheet sheet = dbmc.master_balance_sheets.SingleOrDefault(a => a.shop == master_daily_sale.shop);
            trans.balance_before = sheet != null ? sheet.sales_balance : Decimal.Zero;
            trans.posted_by      = master_daily_sale.posted_by;
            // transaction_category tc = dbmc.transaction_categories.SingleOrDefault(a => a.code == transcode);
            trans.trans_category = tranct.id;
            trans.trans_type     = (tranct.type == true)? 1 : 0;
            trans.amount         = amount;
            calulateBlanaceSheetAfterDailySalesAlter(tranct.type == false ? Decimal.Negate((decimal)trans.amount): (decimal)trans.amount);
            //trans.balance_after = Decimal.Add((decimal)trans.balance_before, (tc.type == false ? Decimal.Negate((decimal)trans.amount): (decimal)trans.amount));
            trans.balance_after = sheet.sales_balance;
            return(trans);
        }
        public master_transaction alter_master_transaction()
        {
            try
            {
                master_transaction prev_master_transaction = db.master_transactions.SingleOrDefault(a => a.id == master_transaction.id);

                prev_master_transaction.amount          = master_transaction.amount;
                prev_master_transaction.balance_before  = master_transaction.balance_before;
                prev_master_transaction.balance_after   = master_transaction.balance_after;
                prev_master_transaction.posted_by       = master_transaction.posted_by;
                prev_master_transaction.shop            = master_transaction.shop;
                prev_master_transaction.trans_category  = master_transaction.trans_category;
                prev_master_transaction.trans_timestamp = master_transaction.trans_timestamp;
                prev_master_transaction.trans_type      = master_transaction.trans_type;



                db.SubmitChanges();
                return(master_transaction);
            }
            catch (Exception)
            {
                return(null);
            }
        }
 public StatementHelper(master_transaction trans)
 {
     Date_    = trans.trans_timestamp.ToShortDateString();
     Debit_   = (trans.trans_type == 1) ? trans.amount.ToString() : string.Empty;
     Credit_  = (trans.trans_type == 0) ? trans.amount.ToString() : string.Empty;
     Balance_ = trans.balance_after.ToString();
     Details_ = (trans.details != string.Empty || trans.details != null) ? trans.details : trans.transaction_category.description;
     trans_   = trans;
 }
 public master_transaction find_master_transaction_By_ID(int id)
 {
     try
     {
         master_transaction = db.master_transactions.SingleOrDefault(a => a.id == id);
         return(master_transaction);
     }
     catch (Exception)
     {
         return(null);
     }
 }
 public master_transaction find_master_transaction_By_AppId(string Appid)
 {
     try
     {
         master_transaction = db.master_transactions.SingleOrDefault(a => a.app_id == Appid);
         return(master_transaction);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        private void LodgeCommission(master_transaction master_transaction, transaction_category tran)
        {
            commission_balance balance = db.commission_balances.SingleOrDefault(a => a.shop == master_transaction.shop);

            if (balance == null)
            {
                balance = new commission_balance
                {
                    shop    = master_transaction.shop.Value,
                    balance = 0
                };
            }

            transaction_category commtran = null;

            if (tran.code == "CR")
            {
                commtran = db.transaction_categories.SingleOrDefault(a => a.code == "CTR");
            }
            else if (tran.code == "C")
            {
                commtran = db.transaction_categories.SingleOrDefault(a => a.code == "CT");
            }
            commission_transaction ctran = new commission_transaction
            {
                amount          = master_transaction.amount,
                balance_after   = getbal(balance.balance, master_transaction.amount, commtran),
                balance_before  = balance.balance,
                description     = master_transaction.details,
                details         = master_transaction.details,
                posted_by       = master_transaction.posted_by,
                shop            = master_transaction.shop,
                trans_category  = commtran.id,
                trans_timestamp = master_transaction.trans_timestamp,
                trans_type      = commtran.type == true ? 1 : 0
            };

            balance.balance = getbal(balance.balance, master_transaction.amount, commtran).Value;


            using (TransactionScope scope = new TransactionScope())
            {
                if (balance.app_id == null)
                {
                    balance.app_id = getAppID().app_id;
                    db.commission_balances.InsertOnSubmit(balance);
                }
                ctran.app_id = getAppID().app_id;
                db.commission_transactions.InsertOnSubmit(ctran);
                db.SubmitChanges();
                scope.Complete();
            }
        }
 public master_transaction delete_master_transaction()
 {
     try
     {
         master_transaction prev_master_transaction = db.master_transactions.SingleOrDefault(a => a.id == master_transaction.id);
         db.master_transactions.DeleteOnSubmit(prev_master_transaction);
         return(master_transaction);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #10
0
 private decimal getOneWeekBalance(List <master_transaction> shoptran, shop shop)
 {
     try
     {
         DateTime date = DateTime.Today.AddDays(-7);
         List <master_transaction> weektran = gettranwithindate(date, DateTime.Today, shoptran);
         master_transaction        maxtran  = getMAxTransaction(weektran, date);
         return((maxtran.balance_before.Value != 0) ? maxtran.balance_before.Value : maxtran.balance_after.Value);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Beispiel #11
0
 private decimal getSixMonthBalance(List <master_transaction> shoptran, shop shop)
 {
     try
     {
         DateTime date     = DateTime.Today.AddMonths(-6);
         DateTime dateprev = DateTime.Today;
         List <master_transaction> mthtran = gettranwithindate(date, dateprev, shoptran);
         master_transaction        maxtran = getMAxTransaction(mthtran, date);
         return((maxtran.balance_before.Value != 0)?maxtran.balance_before.Value : maxtran.balance_after.Value);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Beispiel #12
0
        public void SaveTransaction(bonushelper bhelp, transaction_category bonustransaction, admin_user user)
        {
            master_balance_sheet sendbal;
            transaction_category sendtran;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    master_balance_sheet bal         = db.master_balance_sheets.SingleOrDefault(a => a.shop == bhelp.shop.id);
                    master_transaction   transaction = new master_transaction
                    {
                        amount          = bhelp.Bonus,
                        app_id          = Application().app_id,
                        balance_after   = getbal(bal.sales_balance, bhelp.Bonus, bonustransaction),
                        balance_before  = bal.sales_balance,
                        description     = bonustransaction.description + " " + "for " + fromdate.ToShortDateString() + " - " + todate.ToShortDateString(),
                        details         = bonustransaction.description + " " + "for " + fromdate.ToShortDateString() + " - " + todate.ToShortDateString(),
                        posted_by       = user.id,
                        shop            = bhelp.shop.id,
                        trans_category  = bonustransaction.id,
                        trans_timestamp = DateTime.Now,
                        trans_type      = (bonustransaction.type == true) ? 0 : 1,
                    };

                    db.master_transactions.InsertOnSubmit(transaction);

                    master_balance_sheet prevbal = db.master_balance_sheets.SingleOrDefault(a => a.shop == bhelp.shop.id);
                    prevbal.sales_balance = getbal(bal.sales_balance, bhelp.Bonus, bonustransaction);
                    prevbal.netbalance    = getbal(bal.netbalance, bhelp.Bonus, bonustransaction);

                    sendbal  = prevbal;
                    sendtran = bonustransaction;
                    db.SubmitChanges();

                    scope.Complete();
                }

                SendSms(bhelp, sendbal, sendtran);
            }
            catch (Exception)
            {
            }
        }
Beispiel #13
0
        public List <master_transaction> fillDataToList()
        {
            List <master_transaction> transList = new List <master_transaction>();

            if (dtExcelRecords == null)
            {
                return(null);
            }
            else
            {
                foreach (DataRow row in dtExcelRecords.Rows)
                {
                    int rowindex = dtExcelRecords.Rows.IndexOf(row);
                    //if (dtExcelRecords.Rows.IndexOf(row) == 0)
                    //    continue;
                    //if (dtExcelRecords.Rows.IndexOf(row) == dtExcelRecords.Rows.Count - 1)
                    //    break;
                    //
                    var values = row.ItemArray;
                    master_transaction trans = null;
                    try
                    {
                        trans = db.master_transactions.SingleOrDefault(a => a.id == int.Parse(values[0].ToString()));
                        if (trans != null)//&& values[5].ToString().Length>9)
                        {
                            trans.details = values[1].ToString();
                            transList.Add(trans);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorlist_.Add(trans);
                    }
                }
            }
            list_ = transList;
            return(transList);
        }
Beispiel #14
0
        private decimal LodgeSales(shop shop, decimal bonus, master_balance_sheet shopbal)
        {
            master_transaction tran = new master_transaction()
            {
                amount          = bonus,
                app_id          = Application().app_id,
                balance_after   = getbal(shopbal.sales_balance, bonus, bonustransaction),
                balance_before  = shopbal.sales_balance,
                description     = bonustransaction.description + " " + "for " + fromdate.ToShortDateString() + " - " + todate.ToShortDateString(),
                details         = bonustransaction.description + " " + "for " + fromdate.ToShortDateString() + " - " + todate.ToShortDateString(),
                posted_by       = user.id,
                shop            = shop.id,
                trans_category  = bonustransaction.id,
                trans_timestamp = DateTime.Now,
                trans_type      = (bonustransaction.type == true) ? 0 : 1,
            };


            shopbal.sales_balance = getbal(shopbal.sales_balance, bonus, bonustransaction);
            shopbal.netbalance    = getbal(shopbal.netbalance, bonus, bonustransaction);
            transactionsToSave.Add(tran);
            return(bonus);
        }
Beispiel #15
0
        public master_transaction getMAxTransaction(List <master_transaction> transaction, DateTime date)
        {
            try
            {
                if (transaction != null && transaction.Count() > 0)
                {
                    //List<master_transaction> listdatetran = transaction.Where(a => a.trans_timestamp == date).ToList<master_transaction>();
                    //if (listdatetran != null && listdatetran.Count > 0)
                    //{
                    int id = transaction.Min(a => a.id);
                    master_transaction trans = transaction.SingleOrDefault(a => a.id == id);
                    if (trans.trans_timestamp == lastmindate)
                    {
                        islastdate = true;
                    }
                    else
                    {
                        islastdate = false;
                    }
                    lastmindate = trans.trans_timestamp;
                    return(trans);
                    //}
                    //else
                    //    return null;
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);

                throw;
            }
        }
        public bool SaveMasterLodgementTransaction(master_lodgement_reimbursment newmlr, master_transaction newmastertransaction, master_balance_sheet masterbalance)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    newmastertransaction.app_id = Application().app_id;
                    newmlr.app_id = Application().app_id;

                    db.master_transactions.InsertOnSubmit(newmastertransaction);
                    db.SubmitChanges();

                    newmlr.transaction          = new CRUD.master_transaction_crud().find_master_transaction_By_AppId(newmastertransaction.app_id).id;
                    newmlr.transaction_type     = (newmastertransaction.transaction_category.type == true) ? 1 : 0;
                    newmlr.transaction_category = newmastertransaction.trans_category;
                    db.master_lodgement_reimbursments.InsertOnSubmit(newmlr);

                    master_balance_sheet prev_master_balance_sheet = db.master_balance_sheets.SingleOrDefault(a => a.id == masterbalance.id);

                    prev_master_balance_sheet.credit_balance = masterbalance.credit_balance;
                    prev_master_balance_sheet.netbalance     = masterbalance.netbalance;
                    prev_master_balance_sheet.online_credit  = masterbalance.online_credit;
                    prev_master_balance_sheet.sales_balance  = masterbalance.sales_balance;


                    db.SubmitChanges();

                    scope.Complete();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public bool SaveCutOffTransaction(debt_transaction newdebttransaction, debt debt, master_transaction newmastertransaction, master_balance_sheet masterbalance)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    newmastertransaction.app_id = Application().app_id;
                    debt.app_id = Application().app_id;
                    newdebttransaction.app_id = Application().app_id;


                    db.master_transactions.InsertOnSubmit(newmastertransaction);

                    master_balance_sheet prev_master_balance_sheet = db.master_balance_sheets.SingleOrDefault(a => a.id == masterbalance.id);

                    prev_master_balance_sheet.credit_balance = masterbalance.credit_balance;
                    prev_master_balance_sheet.netbalance     = masterbalance.netbalance;
                    prev_master_balance_sheet.online_credit  = masterbalance.online_credit;
                    prev_master_balance_sheet.sales_balance  = masterbalance.sales_balance;

                    db.debts.InsertOnSubmit(debt);


                    db.SubmitChanges();

                    newdebttransaction.debt = new CRUD.debt_crud().find_debt_By_AppId(debt.app_id).id;

                    db.debt_transactions.InsertOnSubmit(newdebttransaction);

                    db.SubmitChanges();

                    scope.Complete();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public int SaveBalanceList(List <master_balance_sheet> balance, int login, DateTime date)
        {
            int ret = 0;

            try
            {
                foreach (master_balance_sheet bals in balance)
                {
                    master_balance_sheet bal = bals;
                    if (bal.shop != -1)
                    {
                        master_balance_sheet existingbal = new CRUD.master_balance_sheet_crud().find_master_balance_sheet_By_ShopId(bal.shop.Value);

                        if (existingbal == null)
                        {
                            using (TransactionScope scope = new TransactionScope())
                            {
                                master_transaction transaction = new master_transaction
                                {
                                    app_id          = Application().app_id,
                                    amount          = bal.netbalance,
                                    balance_before  = existingbal.netbalance,
                                    balance_after   = Decimal.Add(bal.netbalance.Value, existingbal.netbalance.Value),
                                    description     = "Balance B/D AS AT" + date.ToShortDateString(),
                                    details         = "Balance B/D AS AT " + date.ToShortDateString(),
                                    posted_by       = login,
                                    shop            = bal.shop,
                                    trans_category  = (bal.netbalance >= 0) ? creditbalance.id : debitbalance.id,
                                    trans_timestamp = DateTime.Now,
                                    trans_type      = (bal.netbalance >= 0) ? 0 : 1
                                };
                                db.master_transactions.InsertOnSubmit(transaction);
                                db.master_balance_sheets.InsertOnSubmit(bal);

                                scope.Complete();
                            }
                        }

                        else // (existingbal.netbalance != 0 || existingbal.sales_balance != 0)
                        {
                            using (TransactionScope scope = new TransactionScope())
                            {
                                master_transaction transaction = new master_transaction
                                {
                                    app_id          = Application().app_id,
                                    amount          = bal.netbalance,
                                    balance_before  = existingbal.netbalance,
                                    balance_after   = Decimal.Add(bal.netbalance.Value, existingbal.netbalance.Value),
                                    description     = "Balance B/D AS AT" + date.ToShortDateString(),
                                    details         = "Balance B/D AS AT " + date.ToShortDateString(),
                                    posted_by       = login,
                                    shop            = bal.shop,
                                    trans_category  = (bal.netbalance >= 0) ? creditbalance.id : debitbalance.id,
                                    trans_timestamp = DateTime.Now,
                                    trans_type      = (bal.netbalance >= 0) ? 0 : 1
                                };
                                db.master_transactions.InsertOnSubmit(transaction);


                                bal.id            = existingbal.id;
                                bal.sales_balance = Decimal.Add(bal.sales_balance.Value, existingbal.sales_balance.Value);
                                bal.netbalance    = Decimal.Add(bal.netbalance.Value, existingbal.netbalance.Value);

                                master_balance_sheet prev_master_balance_sheet = db.master_balance_sheets.SingleOrDefault(a => a.id == bal.id);
                                prev_master_balance_sheet.netbalance    = bal.netbalance;
                                prev_master_balance_sheet.sales_balance = bal.sales_balance;
                                db.SubmitChanges();



                                scope.Complete();
                            }
                        }//else if (existingbal.netbalance == 0 && existingbal.sales_balance == 0)
                         //{
                         //    bal = new CRUD.master_balance_sheet_crud(bal).alter_master_balance_sheet();
                         //}
                    }
                    else
                    {
                        ret++;
                    }
                }
            }
            catch (Exception)
            {
                ret++;
            }
            return(ret);
        }
 public master_transaction_crud(master_transaction master_transaction_)
 {
     this.master_transaction_ = master_transaction_;
 }
Beispiel #20
0
        private void AddnewLodgementReimbursementTransaction(shop shop, transaction_category tran, PaymentNotificationRequest pnr, BettingSuiteDataContext db)
        {
            DateTime             date          = DateTime.Today;
            master_balance_sheet masterbalance = new CRUD.master_balance_sheet_crud().getMasterBalanceByShopId(shop.id);

            if (masterbalance == null)
            {
                masterbalance = new master_balance_sheet
                {
                    shop           = shop.id,
                    credit_balance = 0,
                    online_credit  = 0,
                    sales_balance  = 0,
                    netbalance     = 0,
                };
                masterbalance = new CRUD.master_balance_sheet_crud(masterbalance).insert_master_balance_sheet();
            }

            master_transaction reversalmastertransaction = new master_transaction();


            master_lodgement_reimbursment newmlr = new master_lodgement_reimbursment
            {
                amount               = pnr.Amount,
                bank                 = 0,//interswitch id,
                date                 = date,
                shop                 = shop.id,
                teller_number        = pnr.PaymentLogId.ToString(),
                islocked             = true,
                isverified           = true,
                payment_type         = 5,
                transaction_category = tran.id,
            };

            login lodin = db.logins.Single(a => a.username == "InterSwitch");
            master_transaction newmastertransaction = new master_transaction
            {
                amount          = Math.Abs(pnr.Amount),
                balance_before  = (masterbalance != null) ? masterbalance.sales_balance : 0,
                balance_after   = (masterbalance != null) ? getbal(masterbalance.sales_balance, pnr.Amount, tran) : pnr.Amount,
                shop            = shop.id,
                trans_category  = tran.id,
                trans_timestamp = DateTime.Now,
                trans_type      = (tran.type == true) ? 1 : 0,
                posted_by       = lodin.id,// interswitch id,
                description     = pnr.PaymentReference + " Posted For " + date.ToShortDateString(),
                details         = (tran.code == "L") ? "Lodgement For " + date.ToShortDateString() : "Lodgement Reversal For " + date.ToShortDateString()
            };

            masterbalance.sales_balance = (masterbalance != null) ? getbal(masterbalance.sales_balance, newmastertransaction.amount, tran) : newmastertransaction.amount;
            masterbalance.netbalance    = (masterbalance != null) ? getbal(masterbalance.netbalance, newmastertransaction.amount, tran) : newmastertransaction.amount;

            bool loadtran = new Utilities.TransactionHelper().SaveMasterLodgementTransaction(newmlr, newmastertransaction, masterbalance);

            if (loadtran)
            {
                try
                {
                    bool mailvalidity = new Utilities.Mail_Validity_Helper().getMailSendingStatus();
                    SMS_Vendor_Validity_Helper valhelp = new SMS_Vendor_Validity_Helper();
                    sms_vendor vendor = valhelp.getVendorsByName("50kobo");

                    bool smsvalidity = (DateTime.Today <= vendor.expiry_date) ? true : false;

                    if (newmlr.bank1.code != "CASH")
                    {
                        sms message;
                        if (tran.code == "L")
                        {
                            if (smsvalidity)
                            {
                                sm mm = new CRUD.sms_crud().findByCode("CA");
                                message = new sms();

                                if (message.initializeParameters(shop, mm.subject.Trim() + "\r\n" + mm.content.Trim() + "\r\n" + mm.conclusion.Trim(), newmlr))
                                {
                                    message.CustomizeAndSendSMS();
                                }
                            }
                            if (mailvalidity)
                            {
                                mail       mail   = new CRUD.mail_crud().findByCode("LA");
                                MailClient client = new MailClient();
                                client.SendLodgementReimbursementMail(shop, mail, newmastertransaction);
                            }
                        }
                        else if (tran.code == "R")
                        {
                            if (smsvalidity)
                            {
                                sm mm = new CRUD.sms_crud().findByCode("DA");
                                message = new sms();
                                if (message.initializeParameters(shop, mm.subject + "\r\n" + mm.content + "\r\n" + mm.conclusion, newmlr))
                                {
                                    message.CustomizeAndSendSMS();
                                }
                            }
                            if (mailvalidity)
                            {
                                mail       mail   = new CRUD.mail_crud().findByCode("RA");
                                MailClient client = new MailClient();
                                client.SendLodgementReimbursementMail(shop, mail, newmastertransaction);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            else
            {
            }
        }