Ejemplo n.º 1
0
        public bool UpdateStatus(APIEmpIdModel <UpdateWorkOrderStatusModel> model)
        {
            var query      = WorkOrderQueries.UpdateStatus;
            var parameters = DataHelper.ExtractParameters(new { StatusId = model.Model.Status, Id = model.Model.WorkOrderId });

            dbContext.ExecuteNonQuery(query, parameters);
            EventTypes eventType = 0;

            switch (model.Model.Status)
            {
            case 1:
                eventType = EventTypes.WorkOrderDrafted;
                break;

            case 2:
                eventType = EventTypes.WorkOrderCreate;
                break;

            case 3:
                eventType = EventTypes.WorkOrderCancelled;
                break;

            case 4:
                eventType = EventTypes.WorkOrderComplete;
                break;
            }
            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.WorkOrderId, eventType);

            dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));

            return(true);
        }
Ejemplo n.º 2
0
        internal bool LogPrintEvent(APIEmpIdModel <int> model)
        {
            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model, EventTypes.InvoicePrinted);

            dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));
            return(true);
        }
Ejemplo n.º 3
0
        public int Insert(APIEmpIdModel <WorkOrder> model)
        {
            try
            {
                var proposalService = new ProposalService(dbContext);
                var proposal        = proposalService.GetProposalById(model.Model.ProposalId);
                model.Model.BusinessPartnerId        = proposal.BusinessPartnerId;
                model.Model.BusinessPartnerContactId = proposal.BusinessPartnerContactId;
                var query           = WorkOrderQueries.Add;
                var parameters      = DataHelper.ExtractParameters(model.Model);
                var workorderId     = dbContext.Execute <int>(query, parameters);
                var queryLines      = WorkOrderQueries.CopyItemsFromProposal;
                var parametersLines = DataHelper.ExtractParameters(new { WorkOrderId = workorderId, ProposalId = model.Model.ProposalId });
                dbContext.ExecuteNonQuery(queryLines, parametersLines);
                if (proposal.Discount.HasValue)
                {
                    var discountModel = new DiscountView {
                        Discount = proposal.Discount.Value, WorkOrderId = workorderId
                    };
                    var res = ApplyDiscount(discountModel);
                }

                var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, workorderId, EventTypes.WorkOrderDrafted);
                dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));

                return(workorderId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public int UpdateProposalItems(APIEmpIdModel <ProposalItemsUpdateModel> model)
        {
            var queries = new List <QueryWithParameters>();
            var queryUpdateProposalItem = ProposalQueries.UpdateProposalItems;
            var proposalId = model.Model.Items.FirstOrDefault().ProposalId;

            foreach (var item in model.Model.Items)
            {
                if (item.Id == 0)
                {
                    dbContext.ExecuteNonQuery(ProposalQueries.AddProposalItem, DataHelper.ExtractParameters(item));
                }
                else
                {
                    dbContext.ExecuteNonQuery(queryUpdateProposalItem, DataHelper.ExtractParameters(item));
                }
            }
            foreach (var item in model.Model.DeletedItems)
            {
                dbContext.ExecuteNonQuery(ProposalQueries.DeleteProposalItem, DataHelper.ExtractParameters(item));
            }

            var updateQuery  = ProposalQueries.UpdateQuote;
            var updateParams = DataHelper.ExtractParameters(new { TotalAmount = model.Model.TotalAmount, Discount = model.Model.Discount, ProposalId = proposalId });

            dbContext.ExecuteNonQuery(updateQuery, updateParams);

            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, proposalId, EventTypes.QuoteUpdate);

            dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));

            return(dbContext.Get <int>(ProposalQueries.GetQuoteRevisionNo, DataHelper.ExtractParameters(new { ProposalId = proposalId })));
        }
Ejemplo n.º 5
0
        public int Add(APIEmpIdModel <Materials> model)
        {
            try
            {
                //var queryBuilder = new StringBuilder()
                //                    .Append("insert into materials ")
                //                    .Append("(code,name,specification,quantity,shelfnumber) ")
                //                    .Append("values ")
                //                    .Append($"('{newMaterial.Code}','{newMaterial.Name}', ")
                //                    .Append($"'{newMaterial.Specification}',0,'{newMaterial.ShelfNumber}');")
                //                    .Append("SELECT LAST_INSERT_ID();")
                //                    ;

                //var query = queryBuilder.ToString();
                //return dbContext.Execute<int>(query);



                var materialId = dbContext.Get <int>(MaterialsQueries.Insert, DataHelper.ExtractParameters(model.Model));
                if (materialId > 0)
                {
                    var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, materialId, EventTypes.MaterialsCreate);
                    dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));
                    return(materialId);
                }
                else
                {
                    throw new System.Exception("Error adding Material!");
                }
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        public bool ConfirmPurchaseOrder(APIEmpIdModel <int> model)
        {
            var query      = PurchaseOrderQueries.UpdatePurchaseOrderToConfirmed;
            var parameters = DataHelper.ExtractParameters(new{ Id = model.Model });

            dbContext.ExecuteNonQuery(query, parameters);
            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model, EventTypes.PurchaseOrderConfirm);

            dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));
            return(true);
        }
Ejemplo n.º 7
0
        public bool AddCustomerPayment(APIEmpIdModel <CustomerPayments> model)
        {
            var query      = WorkOrderQueries.InsertCustomerPayment;
            var parameters = DataHelper.ExtractParameters(model.Model);

            dbContext.ExecuteNonQuery(query, parameters);

            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.WorkOrderId, EventTypes.CustomerPaymentAdd);

            dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));

            return(true);
        }
Ejemplo n.º 8
0
        public bool AddMaterialUse(APIEmpIdModel <WorkOrderMaterials> model)
        {
            var query      = WorkOrderQueries.AddMaterialUse;
            var parameters = DataHelper.ExtractParameters(new{ MaterialId = model.Model.MaterialId, Units = model.Model.Units, WorkOrderId = model.Model.WorkOrderId });

            dbContext.ExecuteNonQuery(query, parameters);

            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.WorkOrderId, EventTypes.MaterialsConsumptionAdd);

            dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));

            return(true);
        }
Ejemplo n.º 9
0
        public bool AddSupplierPayment(APIEmpIdModel <AddSupplierPaymentModel> model)
        {
            var queryAddPayment      = PurchaseOrderQueries.InsertSupplierPayment;
            var parametersAddPayment = DataHelper.ExtractParameters(model.Model);
            var supplierPaymentId    = dbContext.Execute <int>(queryAddPayment, parametersAddPayment);

            if (supplierPaymentId > 0)
            {
                var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, supplierPaymentId, EventTypes.SupplierPaymentAdd);
                dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));
            }
            return(true);
        }
Ejemplo n.º 10
0
        public int Add(APIEmpIdModel <Suppliers> model)
        {
            var supplierId = dbContext.Get <int>(SupplierQueries.Insert, DataHelper.ExtractParameters(model.Model));

            if (supplierId > 0)
            {
                var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, supplierId, EventTypes.SuppliersCreate);
                dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));
                return(supplierId);
            }
            else
            {
                throw new System.Exception("Error adding Supplier!");
            }
        }
Ejemplo n.º 11
0
        public void SetPurchaseOrderReceiving(APIEmpIdModel <PurchaseOrderDetailedView> model)
        {
            var queries          = new List <QueryWithParameters>();
            var updateItemsQuery = MaterialsQueries.UpdateQuantity;

            foreach (var item in model.Model.Items)
            {
                //Update PO Received Quantity
                var parametersRQ = DataHelper.ExtractParameters(new{ item.ReceivedQuantity, item.Id });
                queries.Add(new QueryWithParameters()
                {
                    Query = PurchaseOrderQueries.UpdatePurchaseOrderItemReceivedQuantity, Parameters = parametersRQ
                });

                //Update Materials Quantity
                var parameters = DataHelper.ExtractParameters(new{ item.ReceivedQuantity, Id = item.MaterialId });
                queries.Add(new QueryWithParameters()
                {
                    Query = updateItemsQuery, Parameters = parameters
                });

                // var parameters=new DynamicParameters();
                // parameters.Add("_Quantity",item.ReceivedQuantity,DbType.Int32,ParameterDirection.Input);
                // parameters.Add("_Id",item.Id,DbType.Int64,ParameterDirection.Input);
                // queries.Add(new QueryWithParameters(){Query=MaterialsQueries.UpdateQuantityProcedure,Parameters=parameters,IsProcedure=true});

                // var updateItemsCountQueryTemplate=MaterialsQueries.UpdateQuantity;
                // var updateItemsCountQuery=updateItemsCountQueryTemplate.Replace("@Quantity",item.ReceivedQuantity.ToString())
                //                      .Replace("@Id",item.Id.ToString());
                // queries.Add(new QueryWithParameters(){Query=updateItemsCountQuery,Parameters=null});
            }
            var queryUpdatePurchaseOrderStatusToReceive = PurchaseOrderQueries.UpdatePurchaseOrderToReceived;
            var status = (model.Model.PartiallyReceived)?4:5;
            var updateStatusParameters = DataHelper.ExtractParameters(new{ model.Model.ReceivedDate, StatusId = status, model.Model.TotalAmount, model.Model.InvoiceNumber, model.Model.Id });

            queries.Add(new QueryWithParameters()
            {
                Query = queryUpdatePurchaseOrderStatusToReceive, Parameters = updateStatusParameters
            });
            var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.Id, EventTypes.PurchaseOrderReceive);

            queries.Add(new QueryWithParameters()
            {
                Query = EventQueries.EventInsert, Parameters = DataHelper.ExtractParameters(erpEvent)
            });
            dbContext.ExecuteTransaction(queries);
        }
Ejemplo n.º 12
0
        public bool UpdateWorkOrderItems(APIEmpIdModel <WorkOrderItemsUpdateModel> model)
        {
            try
            {
                var queries = new List <QueryWithParameters>();
                var queryUpdateWorkOrderItem = WorkOrderQueries.UpdateInvoiceItems;
                var WorkOrderId = model.Model.Items.FirstOrDefault().WorkOrderId;
                foreach (var item in model.Model.Items)
                {
                    if (item.Id == 0)
                    {
                        dbContext.ExecuteNonQuery(WorkOrderQueries.AddInvoiceItem, DataHelper.ExtractParameters(item));
                    }
                    else
                    {
                        dbContext.ExecuteNonQuery(queryUpdateWorkOrderItem, DataHelper.ExtractParameters(item));
                    }
                }
                foreach (var item in model.Model.DeletedItems)
                {
                    dbContext.ExecuteNonQuery(WorkOrderQueries.DeleteWorkOrderItem, DataHelper.ExtractParameters(item));
                }
                var updateQuery  = WorkOrderQueries.UpdateWorkOrderInvoiceAmount;
                var updateParams = DataHelper.ExtractParameters(new { TotalAmount = model.Model.TotalAmount, Discount = model.Model.Discount, WorkOrderId = WorkOrderId });

                dbContext.ExecuteNonQuery(updateQuery, updateParams);

                var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, WorkOrderId, EventTypes.InvoiceUpdate);
                dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 13
0
 public int InsertPurchaseOrderDraft(APIEmpIdModel <PurchaseOrderSimpleView> model)
 {
     try
     {
         model.Model.CreatedDate = DateTime.Now;
         var query           = PurchaseOrderQueries.InsertDraft;
         var parameters      = DataHelper.ExtractParameters(new { SupplierId = model.Model.SupplierId });
         var purchaseOrderId = dbContext.Execute <int>(query, parameters);
         if (purchaseOrderId > 0)
         {
             var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, purchaseOrderId, EventTypes.PurchaseOrderCreate);
             dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent));
             return(purchaseOrderId);
         }
         else
         {
             throw new System.Exception("Error adding Purchase Order!");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 14
0
        public int InsertProposal(APIEmpIdModel <ProposalVM> model)
        {
            try
            {
                var businessPartnerId = 0;
                var contactId         = (model.Model.SelectedContactId == 0)?null: model.Model.SelectedContactId;
                var bpService         = new BusinessPartnerService(dbContext);
                if (model.Model.CreateNew)
                {
                    var bp = new BusinessPartner();
                    bp.Address  = model.Model.Partner.Address;
                    bp.EmailId  = model.Model.Partner.EmailId;
                    bp.MobileNo = model.Model.Partner.MobileNo;
                    bp.VATNo    = model.Model.Partner.VATNo;
                    if (model.Model.IsCompany)
                    {
                        bp.Name = model.Model.Partner.Name;
                        //bp.PointofContact = model.Model.Partner.PointofContact;
                        bp.BusinessPartnerTypeId = (int)BusinessPartnerTypeName.Company;
                    }
                    else
                    {
                        bp.Name = model.Model.PersonName;
                        bp.BusinessPartnerTypeId = (int)BusinessPartnerTypeName.Individual;
                    }
                    businessPartnerId = bpService.Add(bp);
                }
                else
                {
                    if (model.Model.IsCompany)
                    {
                        businessPartnerId = model.Model.SelectedCompanyId.Value;
                    }
                    else
                    {
                        businessPartnerId = model.Model.SelectedPersonId.Value;
                    }
                }

                if (!contactId.HasValue && model.Model.NewContact.Id == 0 && model.Model.NewContact.Name != "Name")
                {
                    var contact = new BusinessPartnerContact();
                    contact.BusinessPartnerId = businessPartnerId;
                    contact.ContactNo         = model.Model.NewContact.ContactNo;
                    contact.Email             = model.Model.NewContact.Email;
                    contact.Name = model.Model.NewContact.Name;
                    contactId    = bpService.AddContact(contact);
                }

                var proposal = new Proposal()
                {
                    BusinessPartnerId        = businessPartnerId,
                    ContactMode              = model.Model.ContactMode,
                    Description              = model.Model.Description,
                    BusinessPartnerContactId = contactId,
                    Discount = (model.Model.Discount.HasValue)? model.Model.Discount.Value:0,
                    VAT      = model.Model.VAT
                };
                var queryAddProposal      = ProposalQueries.AddProposal;
                var parametersAddProposal = DataHelper.ExtractParameters(proposal);
                var proposalId            = dbContext.Get <int>(queryAddProposal, parametersAddProposal);
                model.Model.Items.ForEach(p => p.ProposalId = proposalId);
                var queries = new List <QueryWithParameters>();

                var queryAddProposalItem = ProposalQueries.AddProposalItem;
                foreach (var item in model.Model.Items)
                {
                    var parametersAddProposalItem = DataHelper.ExtractParameters(item);
                    queries.Add(new QueryWithParameters()
                    {
                        Query      = queryAddProposalItem,
                        Parameters = parametersAddProposalItem
                    });
                }

                //Add Event
                var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, proposalId, EventTypes.EnquiryCreate);
                queries.Add(new QueryWithParameters()
                {
                    Query      = EventQueries.EventInsert,
                    Parameters = DataHelper.ExtractParameters(erpEvent)
                });

                dbContext.ExecuteTransaction(queries);
                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }