public ActionResult AddSaleVoucher(int id) { if (service.checkID() == false) { return(Content("IDS Conflict Error Occured While Procsesing Request")); } TemporaryReport temp = service.findTemporaryReport(id); int nextID = id + 1; TemporaryReport tempTo = service.findTemporaryReport(nextID); string from = temp.from_account; string to = temp.to_account; int fromID = (int)temp.tax; double rate = 0; int idForRate = 0; float unitPrice = 0; if (temp.voucher_type == "UPSV" || temp.voucher_type == "UPPV") { try { float checkingUnit = float.Parse(temp.unit_price); } catch (Exception) { if (temp.builty_no_ != null) { return(RedirectToAction("unitPriceSV", "SaleVoucher")); } else { return(RedirectToAction("unitPricePV", "SaleVoucher")); } } } try { int checking = (int)temp.builty_no_; } catch (Exception) { if (temp.voucher_type == "SV") { return(RedirectToAction("Index", "SaleVoucher")); } else { return(RedirectToAction("unitPriceSV", "SaleVoucher")); } } int builty = Convert.ToInt32(temp.builty_no_); try { String session = Session["name"].ToString(); TransactionAccount transFrom = new TransactionAccount(); TransactionAccount trans_to = new TransactionAccount(); Good good = service.findGood(fromID); if (temp.voucher_type == "UPPV" || temp.voucher_type == "PV") { transFrom = service.findJvTransaction(from); trans_to = good.TransactionAccount; idForRate = transFrom.id; } else if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { transFrom = good.TransactionAccount; trans_to = service.findJvTransaction(to); idForRate = trans_to.id; } Transaction tr = new Transaction(); Transaction transTo = new Transaction(); if (temp.voucher_type == "UPSV" || temp.voucher_type == "UPPV") { unitPrice = float.Parse(temp.unit_price); rate = unitPrice; } else { try { rate = service.findRate(idForRate, good.good_Name); } catch (Exception) { return(Content("<script language='javascript' type='text/javascript'>alert('Invalid Rate !');</script>")); } } int amount = 0; tr.truck = temp.truck; tr.builty_no_ = temp.builty_no_; tr.weight_empty = temp.weight_empty; tr.weight_load = temp.weight_load; tr.net_weight = temp.net_weight; tr.quantity = tr.net_weight.ToString(); tr.good_ = good.good_Name; amount = Convert.ToInt32(rate * tr.net_weight); tr.bags = temp.bags; tr.created_at = temp.created_at; tr.updated_at = tr.created_at; tr.is_active = "Y"; tr.code = transFrom.id; tr.description = temp.description; tr.cr = 0; tr.dr = amount; tr.balance = (transFrom.balance - amount); tr.from_account = from; tr.to_account = to; //transFrom.dr_ = amount; if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { if (temp.voucher_type == "SV") { tr.status = "Sale voucher added"; tr.voucher_type = "SV"; // tr.voucher_code = "SV111"; } else { tr.status = "Unit Price Sale Voucher Added"; tr.voucher_type = "UPSV"; // tr.voucher_code = "UPSV111"; } } else { if (temp.voucher_type == "PV") { tr.status = "Purchase Voucher added"; // tr.voucher_code = "PV111"; tr.voucher_type = "PV"; tr.grn = temp.grn; tr.deduction = temp.deduction; } else { tr.status = "Unit Price Purchase Voucher added"; // tr.voucher_code = "UPPV111"; tr.voucher_type = "UPPV"; tr.grn = temp.grn; tr.deduction = temp.deduction; } } tr.trans_acc_id = transFrom.id; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; tr.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); tr.supervisor = Session["username"].ToString(); } tr.user_id = temp.user_id; tr.admin_id = temp.admin_id; tr.voucher_code = temp.voucher_code; tr.unit_price = temp.unit_price; service.addTransaction(tr); transFrom.balance = tr.balance; tr.unique_key = transFrom.id; temp.is_active = "N"; transTo.truck = tempTo.truck; transTo.builty_no_ = tempTo.builty_no_; transTo.weight_empty = tempTo.weight_empty; transTo.weight_load = tempTo.weight_load; transTo.net_weight = tempTo.net_weight; transTo.bags = tempTo.bags; transTo.created_at = tempTo.created_at; transTo.updated_at = tr.created_at; transTo.is_active = "Y"; transTo.quantity = tr.quantity; transTo.good_ = good.good_Name; transTo.code = trans_to.id; transTo.description = tempTo.description; transTo.dr = 0; transTo.cr = amount; transTo.balance = (trans_to.balance + amount); transTo.from_account = from; transTo.to_account = to; if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { if (temp.voucher_type == "SV") { transTo.status = "Sale voucher added"; transTo.voucher_type = "SV"; transTo.voucher_code = "SV111"; } else { transTo.status = "Unit Price Sale Voucher Added"; transTo.voucher_type = "UPSV"; transTo.voucher_code = "UPSV111"; } } else { if (temp.voucher_type == "PV") { transTo.status = "Purchase Voucher added"; transTo.voucher_code = "PV111"; transTo.voucher_type = "PV"; transTo.grn = tempTo.grn; transTo.deduction = tempTo.deduction; } else { transTo.status = "Unit Price Purchase Voucher added"; transTo.voucher_code = "UPPV111"; transTo.voucher_type = "UPPV"; transTo.grn = tempTo.grn; transTo.deduction = tempTo.deduction; } } transTo.trans_acc_id = trans_to.id; //trans_to.cr_ = amount; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transTo.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transTo.supervisor = Session["username"].ToString(); } transTo.user_id = temp.user_id; transTo.admin_id = temp.admin_id; // End // transTo.voucher_code = temp.voucher_code; transTo.unit_price = tr.unit_price; service.addTransaction(transTo); trans_to.balance = transTo.balance; transTo.unique_key = tr.unique_key; tempTo.is_active = "N"; trans_to.updated_at_ = tr.updated_at; transFrom.updated_at_ = tr.updated_at; // for Weight maintenece // //if (tr.voucher_type == "PV" || tr.voucher_type != "UPPV") // if (transFrom.WEIGHT != null) // { // int weight = Convert.ToInt32(transFrom.WEIGHT); // weight = (int)(weight - temp.net_weight); // transFrom.WEIGHT = weight.ToString(); // } // if (trans_to.WEIGHT != null) // { // int weight = Convert.ToInt32(trans_to.WEIGHT); // weight = (int)(weight + temp.net_weight); // trans_to.WEIGHT = weight.ToString(); // } ////////////////////////// tr.Last_Edit = "None"; transTo.Last_Edit = "None"; service.save(); #region Sale and Purchase order if (temp.order_number != 0 && temp.order_number != -1 && temp.order_number != null) { Database1Entities1 db = new Database1Entities1(); if (temp.order_code == "SO") { Sale_Order so = db.Sale_Order.Find(temp.order_number); so.weight = (int)(so.weight - temp.net_weight); if (so.weight <= 0) { so.is_active = "N"; } } else if (temp.order_code == "PO") { Purchase_Order po = db.Purchase_Order.Find(temp.order_number); po.weight = (int)(po.weight - temp.net_weight); if (po.weight <= 0) { po.is_active = "N"; } } db.SaveChanges(); } #endregion service.balanceUpdation(transFrom.id, trans_to.id); ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if (tr.voucher_type == "SV" || tr.voucher_type == "UPSV") { Transaction transaction = new Transaction(); Transaction transactionTo = new Transaction(); TransactionAccount newTr = new TransactionAccount(); try{ newTr = service.findSaleAccount(transFrom.sale_account_id); } catch (Exception) { return(Content("<script language='javascript' type='text/javascript'>alert('Link sale Account not Found !');</script>")); } transaction.truck = tr.truck; transaction.builty_no_ = tr.builty_no_; transaction.weight_empty = tr.weight_empty; transaction.weight_load = tr.weight_load; transaction.net_weight = tr.net_weight; transaction.quantity = tr.quantity; tr.good_ = good.good_Name; amount = Convert.ToInt32(rate * tr.net_weight); transaction.bags = tr.bags; transaction.created_at = tr.created_at; transaction.updated_at = tr.created_at; transaction.is_active = "Y"; transaction.code = transFrom.id; transaction.description = tr.description; transaction.cr = 0; transaction.dr = amount; transaction.balance = (transFrom.balance - amount); transaction.from_account = transFrom.name; transaction.to_account = trans_to.name; //transFrom.dr_ = amount; transaction.status = "Sale voucher added"; transaction.voucher_type = "SV"; transaction.voucher_code = tr.voucher_code; transaction.trans_acc_id = transFrom.id; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transaction.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transaction.supervisor = Session["username"].ToString(); } transaction.user_id = temp.user_id; transaction.admin_id = temp.admin_id; transaction.from_account = transFrom.name; transaction.to_account = newTr.name; transaction.voucher_code = tr.voucher_code; transaction.unique_key = good.Id; transaction.Last_Edit = tr.Last_Edit; service.addTransaction(transaction); transactionTo.truck = tr.truck; transactionTo.builty_no_ = tr.builty_no_; transactionTo.weight_empty = tr.weight_empty; transactionTo.weight_load = tr.weight_load; transactionTo.net_weight = tr.net_weight; transactionTo.bags = tr.bags; transactionTo.created_at = tr.created_at; transactionTo.updated_at = tr.created_at; transactionTo.is_active = "Y"; transactionTo.quantity = tr.quantity; transactionTo.good_ = tr.good_; transactionTo.code = newTr.id; transactionTo.description = tr.description; transactionTo.dr = 0; transactionTo.cr = amount; transactionTo.balance = (trans_to.balance + amount); transactionTo.from_account = transFrom.name; transaction.to_account = newTr.name; transactionTo.status = "Sale voucher added"; transactionTo.voucher_type = "SV"; transactionTo.trans_acc_id = newTr.id; //newTr.cr_ = amount; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transactionTo.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transactionTo.supervisor = Session["username"].ToString(); } transactionTo.user_id = temp.user_id; transactionTo.admin_id = temp.admin_id; transactionTo.from_account = transFrom.name; transactionTo.to_account = newTr.name; transactionTo.Last_Edit = tr.Last_Edit; service.addTransaction(transactionTo); newTr.balance = newTr.balance + amount; newTr.updated_at_ = tr.updated_at; //newTr.dr_ = newTr.dr_ + amount; int weight = Convert.ToInt32(newTr.WEIGHT); int newWieght = (int)(weight + tr.net_weight); newTr.WEIGHT = newWieght.ToString(); transactionTo.voucher_code = tr.voucher_code; transaction.extra = "Sale"; // for dicriminate sale accounts // transactionTo.extra = "Sale"; service.save(); service.balanceUpdation(transFrom.id, newTr.id); } //////////////////////////////////////////////////////////////////////////// return(RedirectToAction("Supervision", "USER_CRUD")); } catch { if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { if (unitPrice == 0) { return(RedirectToAction("Supervision", "USER_CRUD")); //return RedirectToAction("Index"); } else { return(RedirectToAction("Supervision", "USER_CRUD")); //return RedirectToAction("unitPriceSV"); } } else { if (unitPrice == 0) { return(RedirectToAction("purchaseVoucher")); } else { return(RedirectToAction("unitPricePV")); } } } }
public ActionResult ExpensePost(int id) { TemporaryReport temp = service.findTemporaryReport(id); TemporaryReport tempTo = service.findTemporaryReport(id + 1); int transAccID = temp.trans_acc_id; int subHeadID = 0; int headID = 0; string from = temp.from_account; string to = temp.to_account; try { int amount = (int)temp.amount; String session = Session["name"].ToString(); TransactionAccount trans_from = service.findJvTransaction(from); TransactionAccount trans_to = service.findJvTransaction(to); Transaction tr = new Transaction(); Transaction transTo = new Transaction(); tr.created_at = temp.created_at; tr.code = trans_from.id; tr.description = temp.description; tr.dr = amount; tr.cr = 0; tr.balance = (trans_from.balance - amount); tr.updated_at = tr.created_at; tr.is_active = "Y"; tr.from_account = from; tr.to_account = trans_to.name; tr.status = "1"; tr.voucher_type = "EV"; tr.trans_acc_id = trans_from.id; // tr.sub_head_id = trans_from.sub_head_id; // tr.head_id = trans_from.head_id; // tr.main_id = trans_from.main_id; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; tr.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); tr.supervisor = Session["username"].ToString(); } tr.user_id = temp.user_id; tr.admin_id = temp.admin_id; tr.voucher_code = temp.voucher_code; tr.to_account = trans_to.name; service.addTransaction(tr); trans_from.balance = (int)tr.balance; tr.unique_key = trans_from.id; temp.is_active = "N"; //service.save(); transTo.created_at = tempTo.created_at; transTo.code = trans_to.id; transTo.description = tempTo.description; transTo.dr = 0; transTo.cr = amount; transTo.balance = (trans_to.balance + amount); transTo.updated_at = tempTo.updated_at; transTo.is_active = "Y"; transTo.from_account = from; transTo.to_account = trans_to.name; transTo.status = "1"; transTo.voucher_type = "EV"; transTo.trans_acc_id = trans_to.id; // transTo.sub_head_id = trans_to.sub_head_id; // transTo.head_id = trans_to.head_id; // transTo.main_id = trans_to.main_id; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transTo.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transTo.supervisor = Session["username"].ToString(); } transTo.user_id = temp.user_id; transTo.admin_id = temp.admin_id; // End // transTo.voucher_code = tr.voucher_code; transTo.to_account = tr.to_account; service.addTransaction(transTo); trans_to.balance = (int)transTo.balance; transTo.unique_key = tr.unique_key; tempTo.is_active = "N"; trans_from.updated_at_ = tr.updated_at; trans_to.updated_at_ = tr.updated_at; //trans_from.cr_ = trans_from.cr_ + amount; //trans_to.dr_ = trans_to.dr_ + amount; tr.Last_Edit = "None"; transTo.Last_Edit = "None"; service.save(); service.balanceUpdation(trans_from.id, trans_to.id); return(RedirectToAction("Supervision", "USER_CRUD")); } catch { return(RedirectToAction("Index")); } }