public void New(int issuerEntityID, int receiverEntityID, decimal amount, int currencyID) { using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { base.TRANSFER = new transfer() { issuerEntityID = issuerEntityID, receiverEntityID = receiverEntityID, amount = amount, currencyID = currencyID, transferTypeID = (int)TRANSFERTYPE }; ctx.transfers.AddObject(TRANSFER); EXTERNALTSFR = new externalTransfer { ID = TRANSFER.ID }; ctx.externalTransfers.AddObject(EXTERNALTSFR); DBTSFR = new debitTransfer { ID = EXTERNALTSFR.ID }; ctx.debitTransfers.AddObject(DBTSFR); ctx.SaveChanges(); ts.Complete(); } }
/*cancel invoice all payments*/ public void cancelInvoice() { if (INV.Equals(null)) throw new Exception("Invoice Mot Loaded"); using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { /*get all invoice payments*/ List<transfer> transfers = Invoice.getInvoiceAllTransfers(INV.ID); /*cancel payments one by one*/ foreach (var tsfr in transfers) cancelInvoiceTransfer(tsfr.ID); //Get Sum of Invoice Services added decimal invoiceServicesAmt = this.getInvoiceServicesSumAmt(); //Record related transctions List<transaction> transactions = new List<transaction>(); account acc_AP = Account.getAccount((int)INV.order.receiverEntityID, (int)projectEnums.catType.AP, (int)INV.currencyID); var txn1 = new Transaction(+1 * (decimal)invoiceServicesAmt, acc_AP); transactions.Add(txn1.TXN); account acc_AR = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.AR, (int)INV.currencyID); var txn2 = new Transaction(-1 * (decimal)invoiceServicesAmt, acc_AP); transactions.Add(txn2.TXN); /*Record Invoice Transaction*/ this.RecordInvoiceTransaction(transactions, projectEnums.invoiceStatus.Cancelled); ts.Complete(); } }
public List<transaction> cancelTransfer(projectEnums.transferAction tsfrAction) { if (TRANSFER.Equals(null)) throw new Exception("Transfer has not been loaded"); List<transaction> reveresedTransactions=new List<transaction>(); //get Related transacions and input reveres ones using (var ctx = new accountingEntities()) { //Transfer Transactions var Transactions = ctx.transferActions .Join(ctx.sysActionTransactions, ta => ta.ID, sat => sat.sysActionID, (ta, sat) => new { ta,sat}) .Where(x => x.ta.transferID.Equals(TRANSFER.ID)) .Where(x => x.ta.transferActionTypeID.Equals(tsfrAction)) .Join(ctx.transactions, J => J.sat.transactionID, tr => tr.ID, (J, tr) => tr) .ToList(); //enter and save revered Transactions foreach (var txn in Transactions) { account acc = Account.getAccount((int)txn.accountID); var tx = new Transaction(-1 * (decimal)txn.amount, acc); reveresedTransactions.Add(tx.TXN); } //IF PAYMENT ACTION IS REFUND, NEW FEE HANDLING TRANSACTIONS WOULD BE NEEDED } return reveresedTransactions; }
public static account getAccount(int accountID) { account account = new account() { }; using (var ctx = new accountingEntities()) { account = ctx.accounts.Where(x => x.ID.Equals(accountID)).SingleOrDefault(); } return account; }
public void New(service s) { using (var ctx = new accountingEntities()) { SERVICE = s; ctx.services.AddObject(s); ctx.SaveChanges(); } }
public void New(product p) { using (var ctx = new accountingEntities()) { PRODUCT = p; ctx.products.AddObject(p); ctx.SaveChanges(); } }
public static List<transfer> getInvoiceAllTransfers(int invoiceID) { using (var ctx = new accountingEntities()) { var transfers = ctx.invoiceTransfers .Where(x => (int)x.invoiceID == invoiceID) .Select(x => x.transfer) .ToList(); return transfers; } }
public List<card> fetchCards(int entityID) { using (var ctx = new accountingEntities()) { var cardsList = ctx.entityCards .Where(x => x.entityID == entityID) .Select(x => x.card).ToList(); return cardsList; } }
public void Load(int transferID) { using (var ctx = new accountingEntities()) { INTERNALTSFR= ctx.internalTransfers .Where(x => x.ID == transferID) .SingleOrDefault(); if (INTERNALTSFR == null) throw new Exception("no such a EXT Payment Exists"); } }
public void addInvoiceOrderDetail(deliverable newItem) { using (var ctx = new accountingEntities()) { var newOrderDetail = new orderDetail { deliverableID=newItem.ID }; ctx.orderDetails.AddObject(newOrderDetail); ctx.SaveChanges(); } }
public Transaction(decimal amount , account acc) { using (var ctx = new accountingEntities()) { TXN = new transaction { accountID = acc.ID, amount = amount }; ctx.transactions.AddObject(TXN); ctx.SaveChanges(); } }
public void Load(int dbTransferID) { using (var ctx = new accountingEntities()) { var all= ctx.debitTransfers .Where(x => x.ID == dbTransferID) .SingleOrDefault(); DBTSFR = all; base.EXTERNALTSFR = all.externalTransfer; base.TRANSFER = all.externalTransfer.transfer; } }
public void Load(int personEntityId) { using (var ctx = new accountingEntities()) { var person = ctx.people .Where(x => x.ID.Equals(personEntityId)) .SingleOrDefault(); PERSON = person; if (person == null) throw new Exception("no such a Person Exists"); } }
public void addCard(int cardID,int entityID) { using (var ctx = new accountingEntities()) { var person = ctx.people.Where(x => x.ID.Equals(entityID)).SingleOrDefault(); var newEntityCard = new entityCard() { entityID = entityID, cardID = cardID }; ctx.entityCards.AddObject(newEntityCard); ctx.SaveChanges(); } }
public static account getAccount(int entityID, int catTypeID, int currencyID) { account account = new account() { }; using (var ctx = new accountingEntities()) { account = ctx.accounts.Where( x => x.catTypeID == catTypeID && x.ownerEntityID.Equals(entityID) && x.currencyID.Equals(currencyID)) .SingleOrDefault(); } return account; }
public static int getTransferType(int transferID) { int transferTypeID=-1; using (var ctx = new accountingEntities()) { var tsfr = ctx.transfers .Where(x => x.ID.Equals(transferID)) .Select(x => new { transferTypeID=x.transferTypeID }); transferTypeID = (int)tsfr.Single().transferTypeID; } return transferTypeID; }
public static int getExtTransferType(int extTransferID) { int extTransferTypeID = -1; using (var ctx = new accountingEntities()) { var tsfr = ctx.externalTransfers .Where(x => x.ID.Equals(extTransferID)) .Select(x => new { extTransferTypeID = x.externalTsfrTypeID }); extTransferTypeID = (int)tsfr.Single().extTransferTypeID; } return extTransferTypeID; }
protected static void addWalletMoney(decimal amount, string title, int currencyID, int entityID) { using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { //Record related transctions List<transaction> transactions = new List<transaction>(); account acc_W= Account.getAccount(entityID, (int)projectEnums.catType.W, currencyID); var trans1 = new Transaction( +1 * (decimal)amount, acc_W); transactions.Add(trans1.TXN); account acc_CCCASH = Account.getAccount(entityID, (int)projectEnums.catType.CCCASH, currencyID); var trans2 = new Transaction(-1 * (decimal)amount, acc_CCCASH); transactions.Add(trans2.TXN); ts.Complete(); } }
public void New(string firstName,string lastName) { using (var ctx = new accountingEntities()) { var checkDuplication = ctx.people.Where(x => x.firstname == firstName && x.lastname == lastName).FirstOrDefault(); if (checkDuplication != null) throw new Exception("Person Duplicated"); var newPerson = new person() { firstname=firstName, lastname=lastName, ID = base.ENTITY.ID }; ctx.people.AddObject(newPerson); ctx.SaveChanges(); this.PERSON = newPerson; } }
public void New(string CurrencyName, int currencyTypeID) { using (var ctx = new accountingEntities()) { var newCur = new currency { currencyTypeID = currencyTypeID, name = CurrencyName }; var result = ctx.currencies.FirstOrDefault(x => x.name.Equals(CurrencyName) && x.currencyTypeID.Equals(currencyTypeID)); if (result != null) throw new Exception("Currency Duplicated"); else { ctx.currencies.AddObject(newCur); ctx.SaveChanges(); } } }
public account Create(int ownerEntityId,int currencyID,decimal balance=0) { using (var ctx = new accountingEntities()) { var duplicate = ctx.accounts .Where(x => x.ownerEntityID == ownerEntityId && x.currencyID == currencyID && x.catTypeID ==CATTYPE) .SingleOrDefault(); if (duplicate != null) ctx.DeleteObject(duplicate); var newAccount = new account() { catTypeID=CATTYPE, ownerEntityID=ownerEntityId, currencyID=currencyID, balance=balance }; ctx.accounts.AddObject(newAccount); ctx.SaveChanges(); return newAccount; } }
public void Load(int invoiceID) { using (var ctx = new accountingEntities()) { INV = ctx.invoices.Where(x => x.ID.Equals(invoiceID)).FirstOrDefault(); if (INV == null) throw new Exception("Invoice does not exists"); } }
public void finalizeInvoice() { using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { //Get Sum of Invoice Services added decimal invoiceServicesAmt = this.getInvoiceServicesSumAmt(); //Record related transctions List<transaction> transactions = new List<transaction>(); account acc_AP = Account.getAccount((int)INV.order.receiverEntityID, (int)projectEnums.catType.AP, (int)INV.currencyID); var trans1 = new Transaction(-1 * (decimal)invoiceServicesAmt, acc_AP); transactions.Add(trans1.TXN); account acc_AR = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.AR, (int)INV.currencyID); var trans2 = new Transaction(+1 * (decimal)invoiceServicesAmt, acc_AR); transactions.Add(trans2.TXN); /*Record Invoice Transaction*/ this.RecordInvoiceTransaction(transactions, projectEnums.invoiceStatus.Finalized); ts.Complete(); } }
private void RecordInvoiceTransferTransactions(List<transaction> txns, int transferID, projectEnums.transferStatus transferStat) { using (var ctx = new accountingEntities()) { //Create Payment Action var transferAction = new transferAction() { transferID = transferID, transferStatusID = (int)transferStat }; ctx.transferActions.AddObject(transferAction); ctx.SaveChanges(); //Record Pyament Action TXNS foreach (var txn in txns) { var NewsysActionTxn = new sysActionTransaction() { sysActionID = -1, transactionID = txn.ID }; ctx.sysActionTransactions.AddObject(NewsysActionTxn); ctx.SaveChanges(); } } }
public void RecordInvoiceTransaction(List<transaction> transactions, projectEnums.invoiceStatus invoiceStat) { if (INV.Equals(null)) throw new Exception("Invoice does not exists"); using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { //create invoice Action var invAction = new invoiceAction() { invoiceID = INV.ID, invoiceStatusID = (int)invoiceStat }; ctx.invoiceActions.AddObject(invAction); ctx.SaveChanges(); //create invoice Transactions and invoice action Transactions foreach (var item in transactions) { var invActionTrans = new sysActionTransaction() { sysActionID = invAction.ID, transactionID = item.ID }; ctx.sysActionTransactions.AddObject(invActionTrans); ctx.SaveChanges(); } ts.Complete(); } }
public decimal getInvoiceServicesSumAmt() { using (var ctx = new accountingEntities()) { var inv = ctx.invoices.Where(x => x.ID.Equals(INV.ID)).SingleOrDefault(); if (inv == null) throw new Exception(); decimal invoiceServicesAmt = 0; invoiceServicesAmt = ctx.orderDetails .Where(x=>x.orderID.Equals(inv.orderID)) .Sum(x => x.unitPrice*x.quantity).Value; return (decimal)invoiceServicesAmt; } }
/*Payment for Invoice*/ public void Transfer_Internal(decimal amount) { if (INV.Equals(null)) throw new Exception("No invocie set.pleae laod or create new Invoice"); using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { //create new Internal Payment InternalTransfer iPayment = new InternalTransfer(); iPayment.New((int)INV.order.receiverEntityID, (int)INV.order.issuerEntityID, amount, (int)INV.currencyID); /*Record New Invoice Payment*/ var NewInvTransfer= new invoiceTransfer() { invoiceID = INV.ID, transferID = iPayment.TRANSFER.ID }; ctx.invoiceTransfers.AddObject(NewInvTransfer); ctx.SaveChanges(); //Record related transctions [for invoice payment] List<transaction> transactions = new List<transaction>(); account acc_W = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.W, (int)INV.currencyID); var t1 = new Transaction(-1 * (decimal)amount, acc_W); transactions.Add(t1.TXN); account acc_AP = Account.getAccount((int)INV.order.receiverEntityID, (int)projectEnums.catType.AP, (int)INV.currencyID); var t2 = new Transaction(+1 * (decimal)amount, acc_AP); transactions.Add(t2.TXN); account acc_W2 = Account.getAccount((int)INV.order.receiverEntityID, (int)projectEnums.catType.W, (int)INV.currencyID); var t3 = new Transaction(+1 * (decimal)amount, acc_W2); transactions.Add(t3.TXN); account acc_AR = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.AR, (int)INV.currencyID); var t4 = new Transaction(-1 * (decimal)amount, acc_AR); transactions.Add(t4.TXN); /*Record Invoice Payment transactions*/ this.RecordInvoiceTransferTransactions(transactions, (int)iPayment.TRANSFER.ID, projectEnums.transferStatus.PaidApproved); /*Record Invoice Transaction*/ this.RecordInvoiceTransaction(transactions, projectEnums.invoiceStatus.internalTransfer); ts.Complete(); } }
public void New(invoice inv) { INV = inv; using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { //Entity var e = new entity{entityTypeID = (int)projectEnums.entityType.invoice}; ctx.entities.AddObject(e); //New Invoice var newInvoice = new invoice() { currencyID = inv.currencyID, ID=e.ID }; //sys Action var sysaction = new sysAction{sysActionTypeID=(int)projectEnums.sysAction.invoice}; ctx.sysActions.AddObject(sysaction); //sys Action Invoice var sysActionInvoice = new invoiceAction { ID = sysaction.ID, invoiceStatusID= (int)projectEnums.invoiceStatus.Generated, name="Invoice Generated at "+DateTime.Now.ToLongTimeString() }; ctx.invoiceActions.AddObject(sysActionInvoice); ctx.SaveChanges(); ts.Complete(); } }
/*cancelling one Transfer OR invoice at the time*/ public void cancelInvoiceTransfer(int transferID) { using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { ITransfer invTrasfer=null; var extTransferTypeID = -1; var transferTypeID = Transfer.getTransferType(transferID); switch (transferID) { case 1: extTransferTypeID = ExternalTransfer.getExtTransferType(transferID); if(extTransferTypeID.Equals(1)) invTrasfer = (ITransfer)new CreditTransfer(); else invTrasfer = (ITransfer)new DebitTransfer(); break; case 2: invTrasfer = (ITransfer)new InternalTransfer(); break; } List<transaction> transactions = invTrasfer.cancelTransfer(projectEnums.transferAction.Void); /*Record Invoice Payment transactions*/ this.RecordInvoiceTransferTransactions(transactions, transferID, projectEnums.transferStatus.VoidApproved); /*Record Invoice Transaction*/ if (!extTransferTypeID.Equals(-1)) { if (extTransferTypeID == (int)projectEnums.extTransferType.CreditPayment) this.RecordInvoiceTransaction(transactions, projectEnums.invoiceStatus.partialCreditCardTransferCancelled); if (extTransferTypeID == (int)projectEnums.extTransferType.InteracPayment) this.RecordInvoiceTransaction(transactions, projectEnums.invoiceStatus.partialInteracTransferCancelled); } else { this.RecordInvoiceTransaction(transactions, projectEnums.invoiceStatus.partialInternalTransferCancelled); } ts.Complete(); } }
public void Transfer_Ext_Credit(decimal amount, int cardID, projectEnums.ccCardType ccCardType) { if (INV.Equals(null)) throw new Exception("No invocie set.pleae laod or create new Invoice"); using (var ctx = new accountingEntities()) using (var ts = new TransactionScope()) { //create new Internal Payment CreditTransfer ccPayment = new CreditTransfer(); ccPayment.New((int)INV.order.receiverEntityID, (int)INV.order.issuerEntityID, amount, (int)INV.currencyID); /*Record New Invoice Payment*/ var NewInvTransfer = new invoiceTransfer() { invoiceID = INV.ID, transferID = ccPayment.TRANSFER.ID }; ctx.invoiceTransfers.AddObject(NewInvTransfer); ctx.SaveChanges(); //Record related transctions [for invoice Transfer] var FEE = 1; List<transaction> transactions = new List<transaction>(); account acc_CCCASH = Account.getAccount((int)INV.order.receiverEntityID, (int)projectEnums.catType.CCCASH, (int)INV.currencyID); var t1 = new Transaction(-1 * (decimal)amount, acc_CCCASH); transactions.Add(t1.TXN); account acc_AP = Account.getAccount((int)INV.order.receiverEntityID, (int)projectEnums.catType.AP, (int)INV.currencyID); var t2 = new Transaction(+1 * (decimal)amount, acc_AP); transactions.Add(t2.TXN); account acc_W = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.W, (int)INV.currencyID); var t3 = new Transaction(+1 * (decimal)amount - FEE, acc_W); transactions.Add(t3.TXN); account acc_AR = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.AR, (int)INV.currencyID); var t4 = new Transaction(-1 * (decimal)amount, acc_AR); transactions.Add(t4.TXN); account acc_EXP = Account.getAccount((int)INV.order.issuerEntityID, (int)projectEnums.catType.AR, (int)INV.currencyID); var t5 = new Transaction(FEE, acc_EXP); transactions.Add(t5.TXN); /*Record Invoice Payment transactions*/ this.RecordInvoiceTransferTransactions(transactions, ccPayment.TRANSFER.ID, projectEnums.transferStatus.PaidApproved); /*Record Invoice Transaction*/ projectEnums.invoiceStatus? invoicestat = null; switch (ccCardType) { case projectEnums.ccCardType.MASTERCARD: invoicestat = projectEnums.invoiceStatus.masterCardTransfer; break; case projectEnums.ccCardType.VISACARD: invoicestat = projectEnums.invoiceStatus.visaCardTransfer; break; } this.RecordInvoiceTransaction(transactions, (projectEnums.invoiceStatus)invoicestat); ts.Complete(); } }