Esempio n. 1
0
        public GetWorkOrderClientSerialNoResponseDto GetWorkOrderClientSerialNo(string shortCode)
        {
            var response = new GetWorkOrderClientSerialNoResponseDto();

            var model = workOrderTypeRepository.GetWorkOrderClientSerialNo(shortCode);

            return(response);
        }
        public WorkOrderResponseDto AddWorkOrder(WorkOrderRequestDto workOrderRequestDto)
        {
            var    getWorkOrderClientSerialNoQM = new GetWorkOrderClientSerialNoQM();
            string ClientSerialStartName        = System.Configuration.ConfigurationManager.AppSettings["ClientStartName"].ToString();
            string CurrentMonth      = Constant.GetMonthByAlphabet(System.DateTime.UtcNow.Month);
            string CurrentYear       = Constant.GetYearByAlphabet(System.DateTime.UtcNow.Year);
            var    clientSerialDigit = ClientSerialStartName + CurrentYear + CurrentMonth;

            getWorkOrderClientSerialNoQM = workOrderRepository.GetWorkOrderClientSerialNo(clientSerialDigit);

            string clientSerialNo            = "";
            string clientSerialNumber        = "";
            var    existingclientSerialDigit = "";

            if (!string.IsNullOrEmpty(getWorkOrderClientSerialNoQM.WorkOrderClientSerialNo))
            {
                clientSerialNumber        = getWorkOrderClientSerialNoQM.WorkOrderClientSerialNo.ToString();
                existingclientSerialDigit = getWorkOrderClientSerialNoQM.WorkOrderClientChar;
            }

            #region Section For to save the work order master common details
            workOrderRepository.AddWorkOrderMasterCommon(workOrderRequestDto.WorkOrderType, workOrderRequestDto.WorkOrderNumber, workOrderRequestDto.WorkOrderDate, workOrderRequestDto.VendorCode);
            #endregion

            #region Section For to save the work order masters information & work order details

            foreach (var workOrderMaster in workOrderRequestDto.WorkOrderMasterDetails)
            {
                var workOrderMasterItems = new List <WorkOrderMasterItems>();

                var cModel = new AddWorkOrderCM();
                var workOrderMasterDetails = new WorkOrderMasterItems
                {
                    WorkOrderNumber    = workOrderMaster.WorkOrderNumber,
                    WorkOrderSerial    = workOrderMaster.WorkOrderSerial,
                    DCNumber           = workOrderMaster.DCNumber,
                    DCDate             = workOrderMaster.DCDate,
                    DCSerial           = workOrderMaster.DCSerial,
                    PONumber           = workOrderMaster.PONumber,
                    PODate             = workOrderMaster.PODate,
                    POSerial           = workOrderMaster.POSerial,
                    DrawingNo          = workOrderMaster.DrawingNo,
                    DrawingRev         = workOrderMaster.DrawingRev,
                    PartCode           = workOrderMaster.PartCode,
                    WOQuantity         = workOrderMaster.WOQuantity,
                    Rate               = workOrderMaster.Rate,
                    DeliveryDate       = workOrderMaster.DeliveryDate,
                    DCQuantity         = 0,
                    RejectedQuantity   = 0,
                    InvoicedQuantity   = 0,
                    SCSentQuantity     = 0,
                    SCReceivedQuantity = 0,
                    CreatedBy          = workOrderMaster.CreatedBy,
                    CreatedDateTime    = workOrderMaster.CreatedDateTime,
                    VendorCode         = workOrderMaster.VendorCode,
                    MaterialCode       = workOrderMaster.MaterialCode,
                    ItemCode           = workOrderMaster.ItemCode,
                    HeatNo             = workOrderMaster.HeatNo
                };

                workOrderMasterItems.Add(workOrderMasterDetails);

                cModel.WorkOrderMasterListItems = workOrderMasterItems;

                // Section to add the work order master information
                var response = workOrderRepository.AddWorkOrder(cModel);



                // Section to add the work order details information
                var quantity        = cModel.WorkOrderMasterListItems.FirstOrDefault().WOQuantity;
                var heatNo          = cModel.WorkOrderMasterListItems.FirstOrDefault().HeatNo;
                var woSerialNo      = cModel.WorkOrderMasterListItems.FirstOrDefault().WorkOrderSerial;
                var workOrderNumber = cModel.WorkOrderMasterListItems.FirstOrDefault().WorkOrderNumber;

                if (!string.IsNullOrEmpty(clientSerialNumber))
                {
                    //var existingclientSerialDigit = clientSerialNo.ToString().Substring(0, 3);

                    if (!clientSerialDigit.Equals(existingclientSerialDigit))
                    {
                        string serialNoStarting = "0";
                        clientSerialNo = clientSerialDigit + serialNoStarting;
                    }
                    else
                    {
                        clientSerialNo = existingclientSerialDigit + clientSerialNumber;
                    }
                }
                else
                {
                    string serialNoStarting = "0";
                    clientSerialNo = clientSerialDigit + serialNoStarting;
                }

                for (int i = 0; i < quantity; i++)
                {
                    var splitSerialChar = clientSerialNo.ToString().Substring(0, 3);
                    var splitSerialNo   = clientSerialNo.ToString().Substring(3);
                    clientSerialNo            = splitSerialChar + ((Convert.ToInt64(splitSerialNo) + 1));
                    clientSerialNumber        = ((Convert.ToInt64(splitSerialNo) + 1)).ToString();
                    existingclientSerialDigit = splitSerialChar;
                    WorkOrderDetailsCM workOrderDetailsCM = new WorkOrderDetailsCM()
                    {
                        WorkOrderNumber = workOrderNumber,
                        WorkOrderSerial = woSerialNo,
                        SerialNo        = clientSerialNo,
                        HeatNo          = heatNo,
                        Invoice         = false,
                        JTC             = false,
                        SubContract     = false,
                        DC = false,
                        CreatedDateTime = System.DateTime.UtcNow
                    };
                    workOrderRepository.AddWorkOrderDetails(workOrderDetailsCM);
                }
            }

            #endregion


            return(new WorkOrderResponseDto());
        }