public bool checkExistBillActorInOrgan(Session session, Guid organId) { try { CriteriaOperator criteria = new BinaryOperator("OrganizationId", organId); BillActor billActor = session.FindObject <BillActor>(criteria); if (billActor == null) { return(false); } return(true); } catch (Exception e) { throw; } }
protected override void CloneBillActorData(Session session, Guid billId, ref Bill ret) { NAS.DAL.Invoice.SalesInvoice source = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId); foreach (var sourceBillActor in source.BillActors) { BillActor billActor = new BillActor(session) { BillActorTypeId = sourceBillActor.BillActorTypeId, BillId = ret, OrganizationId = sourceBillActor.OrganizationId, PersonId = sourceBillActor.PersonId }; billActor.Save(); } }
public BillActor BillActorInit(Session session, Guid BillActorId, short ActorType, Guid OrganizationId, Guid PersonId, Guid BillId ) { BillActor billActor = new BillActor(session); billActor.BillActorId = BillActorId; //billActor.ActorType = ActorType; billActor.OrganizationId = session.GetObjectByKey <Organization>(OrganizationId); billActor.PersonId = session.GetObjectByKey <Person>(PersonId); billActor.BillId = session.GetObjectByKey <Bill>(BillId); return(billActor); }
public bool UpdateBillActor(Session session, Guid billId, Guid creatorPersonId, Guid salesPersonId, Guid chiefAccountantPersonId, Guid directorPersonId) { try { //Get bill Bill bill = session.GetObjectByKey <Bill>(billId); if (bill == null) { throw new Exception("Could not foung bill"); } //Get creator Person creator = session.GetObjectByKey <Person>(creatorPersonId); Person sales = session.GetObjectByKey <Person>(salesPersonId); Person chiefAccountant = session.GetObjectByKey <Person>(chiefAccountantPersonId); Person director = session.GetObjectByKey <Person>(directorPersonId); int countExistType; BillActorType creatorType; //Update CREATOR bill actor type creatorType = BillActorType.GetDefault(session, BillActorTypeEnum.CREATOR); countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType); if (countExistType == 0) { BillActor billActor = new BillActor(session) { BillActorTypeId = creatorType, PersonId = creator, BillId = bill }; } else { BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType); billActor.PersonId = creator; } session.FlushChanges(); //Update SALES bill actor type creatorType = BillActorType.GetDefault(session, BillActorTypeEnum.SALES); countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType); if (countExistType == 0) { BillActor billActor = new BillActor(session) { BillActorTypeId = creatorType, PersonId = sales, BillId = bill }; } else { BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType); billActor.PersonId = sales; } session.FlushChanges(); //Update CHIEFACCOUNTANT bill actor type creatorType = BillActorType.GetDefault(session, BillActorTypeEnum.CHIEFACCOUNTANT); countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType); if (countExistType == 0) { BillActor billActor = new BillActor(session) { BillActorTypeId = creatorType, PersonId = chiefAccountant, BillId = bill }; } else { BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType); billActor.PersonId = chiefAccountant; } session.FlushChanges(); //Update DIRECTOR bill actor type creatorType = BillActorType.GetDefault(session, BillActorTypeEnum.DIRECTOR); countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType); if (countExistType == 0) { BillActor billActor = new BillActor(session) { BillActorTypeId = creatorType, PersonId = director, BillId = bill }; } else { BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType); billActor.PersonId = director; } session.FlushChanges(); return(true); } catch (Exception) { throw; } }
///////////////////////////////////////////////// public Guid insertEmptyPurchaseInvoice(Session session) { NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice = new NAS.DAL.Invoice.PurchaseInvoice(session); purchaseInvoice.BillId = Guid.NewGuid(); purchaseInvoice.RowStatus = -1; purchaseInvoice.PurchasingStatus = "PO"; purchaseInvoice.Save(); XPCollection <BillActorType> collectBillActorType = new XPCollection <BillActorType>(session); if (collectBillActorType.Count <= 0) { BillActorType billActorType = new BillActorType(session); billActorType.Description = "Người lập phiếu"; billActorType.Name = "CREATOR"; billActorType.RowStatus = Constant.ROWSTATUS_ACTIVE; billActorType.Save(); billActorType = new BillActorType(session); billActorType.Description = "Người mua hàng"; billActorType.Name = "BUYER"; billActorType.RowStatus = Constant.ROWSTATUS_ACTIVE; billActorType.Save(); billActorType = new BillActorType(session); billActorType.Description = "Người bán hàng"; billActorType.Name = "SALES"; billActorType.RowStatus = Constant.ROWSTATUS_ACTIVE; billActorType.Save(); billActorType = new BillActorType(session); billActorType.Description = "Kế toán trưởng"; billActorType.Name = "CHIEFACCOUNTANT"; billActorType.RowStatus = Constant.ROWSTATUS_ACTIVE; billActorType.Save(); billActorType = new BillActorType(session); billActorType.Description = "Giám đốc"; billActorType.Name = "DIRECTOR"; billActorType.RowStatus = Constant.ROWSTATUS_ACTIVE; billActorType.Save(); } collectBillActorType = new XPCollection <BillActorType>(session); foreach (BillActorType billActorType in collectBillActorType) { BillActor billActor = new BillActor(session); billActor.BillId = purchaseInvoice; billActor.BillActorTypeId = billActorType; billActor.Save(); } return(purchaseInvoice.BillId); }
protected void grdPurchase_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { string[] p = e.Parameters.Split('|'); switch (p[0]) { case "copy": Guid id = Guid.Parse(p[1].ToString()); Bill bill = session.GetObjectByKey <Bill>(id); if (bill != null) { ArtifactCodeRuleBO artifactCodeRuleBO = new ArtifactCodeRuleBO(); Bill billCopy = new Bill(session); billCopy.BillId = new Guid(); billCopy.Code = bill.Code + "_copy"; billCopy.RowStatus = 1; billCopy.TargetOrganizationId = bill.TargetOrganizationId; billCopy.SourceOrganizationId = bill.SourceOrganizationId; CriteriaOperator filter = new BinaryOperator("Code", billCopy.Code, BinaryOperatorType.Equal); Bill billTest = session.FindObject <Bill>(filter); if (billTest == null) { billCopy.Save(); } else { grdPurchase.JSProperties.Add("cpCopyFailed", billCopy.Code); return; } filter = new BinaryOperator("BillId", id, BinaryOperatorType.Equal); XPCollection <BillActor> collectBillActor = new XPCollection <BillActor>(session, filter); foreach (BillActor ba in collectBillActor) { BillActor billActor = new BillActor(session); billActor.BillId = billCopy; billActor.BillActorId = Guid.NewGuid(); billActor.BillActorTypeId = ba.BillActorTypeId; billActor.OrganizationId = ba.OrganizationId; billActor.PersonId = ba.PersonId; billActor.Save(); } filter = new BinaryOperator("BillId", id, BinaryOperatorType.Equal); XPCollection <BillItem> collectBillItem = new XPCollection <BillItem>(session, filter); foreach (BillItem bi in collectBillItem) { BillItem billItem = new BillItem(session); billItem.BillId = billCopy; billItem.RowStatus = 1; billItem.BillItemId = bi.BillItemId; billItem.LotId = bi.LotId; billItem.Price = bi.Price; billItem.PromotionInNumber = bi.PromotionInNumber; billItem.PromotionInPercentage = bi.PromotionInPercentage; billItem.Quantity = bi.Quantity; billItem.TotalPrice = bi.TotalPrice; billItem.Save(); filter = new BinaryOperator("BillItemId", id, BinaryOperatorType.Equal); XPCollection <BillItemTax> collectBillItemTax = new XPCollection <BillItemTax>(session, filter); foreach (BillItemTax bit in collectBillItemTax) { BillItemTax billItemTax = new BillItemTax(session); billItemTax.BillItemId = billItem; billItemTax.BillItemTaxId = Guid.NewGuid(); billItemTax.ItemTaxId = bit.ItemTaxId; billItemTax.TaxInNumber = bit.TaxInNumber; billItemTax.TaxInPercentage = bit.TaxInPercentage; billItemTax.Save(); } } grdPurchase.JSProperties.Add("cpRefresh", billCopy.Code); } break; default: break; } }