Esempio n. 1
0
        public byte[] GetDispatchPDF(int dispatchId, bool ifSendEmail = false)
        {
            if (UserHelper.IsAuthorize(new List <int> {
                (int)UserType.SuperAdmin, (int)UserType.Admin, (int)UserType.Client
            }))
            {
                try
                {
                    DispatchDetailsPDF dispatchInfoToPDF = _dispatchManager.GetDispatchDetails(dispatchId);
                    Dispatch           dispatch          = _context.Dispatches.FirstOrDefault(d => d.Id == dispatchId && d.Deleted_At == null);
                    User   userCreator = _context.Users.FirstOrDefault(u => u.Id == dispatch.Creator_Id && u.Deleted_at == null);
                    string creatorName = "";
                    if (userCreator != null)
                    {
                        creatorName = userCreator.Login;//zmienic na imie i nazwisko
                    }

                    byte[] result = _pdfManager.GenerateDispatchPDF(dispatchInfoToPDF, creatorName);
                    if (ifSendEmail)
                    {
                        _pdfManager.SendEmail("Dispatch_" + dispatch.Dispatch_Number, result);
                    }
                    return(result);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }

            else
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User don't have acces to this method"));
            }
        }
Esempio n. 2
0
        public DispatchDetailsPDF GetDispatchDetails(int dispatchId)
        {
            DispatchDetailsPDF result = new DispatchDetailsPDF();
            List <OrderPositionsDispatchInfoPDF> listOfOrderPositionsDispatchInfoPDF = new List <OrderPositionsDispatchInfoPDF>();
            Dispatch       dispatch    = _context.Dispatches.FirstOrDefault(d => d.Id == dispatchId && d.Deleted_At == null);
            int            cmrId       = Convert.ToInt32(dispatch.CMR_Id);
            CMR_Dispatches cmrDispatch = _context.CMR_Dispatches.FirstOrDefault(c => c.Id == cmrId && c.Deleted_At == null);
            List <Dispatches_Positions> dispatchPositions = _context.Dispatches_Positions.Where(d => d.Dispatch_Id == dispatchId && d.Deleted_At == null).ToList();

            foreach (var item in dispatchPositions)
            {
                Orders_Positions orderPosition            = _context.Orders_Positions.FirstOrDefault(o => o.Id == item.Order_Position_Id && o.Deleted_At == null);
                Order            order                    = _context.Orders.FirstOrDefault(o => o.Id == orderPosition.Order_id && o.Deleted_At == null);
                OrderPositionsDispatchInfoPDF toAddToList = new OrderPositionsDispatchInfoPDF();
                int?     amountReceived                   = orderPosition.Amount_Received;
                decimal? weightReceived                   = orderPosition.Weight_Gross_Received;
                DateTime dateDispatch = dispatch.Created_At.Value.AddMilliseconds(-1);//bo znak mniejszośc działa jak <=
                List <Dispatches_Positions> listOfdispatchesPositionsForOrderPosition = _context.Dispatches_Positions.Where(d => d.Order_Position_Id == orderPosition.Id && d.Deleted_At == null && d.Created_At.Value < dateDispatch).ToList();
                int?    amountBeforeDispatch = amountReceived - listOfdispatchesPositionsForOrderPosition.Sum(d => d.Amount);
                decimal?weightBeforeDispatch = weightReceived - listOfdispatchesPositionsForOrderPosition.Sum(d => d.Weight_Gross);
                int?    amountDispatch       = item.Amount;
                decimal?weightDispatch       = item.Weight_Gross;
                toAddToList.Id                     = item.Id;
                toAddToList.ATB                    = order.ATB;
                toAddToList.Container_Id           = order.Container_Id;
                toAddToList.Name                   = orderPosition.Name;
                toAddToList.Amount_Received        = amountReceived;
                toAddToList.Weight_Gross_Received  = weightReceived;
                toAddToList.Amount_Before_Dispatch = amountBeforeDispatch;
                toAddToList.Weight_Before_Dispatch = weightBeforeDispatch;
                toAddToList.Amount_Dispatch        = amountDispatch;
                toAddToList.Weight_Dispatch        = weightDispatch;
                listOfOrderPositionsDispatchInfoPDF.Add(toAddToList);
            }

            CarrierDispatch carrierDispatch = new CarrierDispatch();

            carrierDispatch.Carrier_Address = dispatch.Carrier_Address;
            carrierDispatch.Carrier_Email   = dispatch.Carrier_Email;
            carrierDispatch.Carrier_Name    = dispatch.Carrier_Name;
            carrierDispatch.Carrier_VAT_Id  = dispatch.Carrier_VAT_Id;

            ReceiverDispatch receiverDispatch = new ReceiverDispatch();

            receiverDispatch.Receiver_Address = dispatch.Receiver_Address;
            receiverDispatch.Receiver_Email   = dispatch.Receiver_Email;
            receiverDispatch.Receiver_Name    = dispatch.Receiver_Name;
            receiverDispatch.Receiver_VAT_Id  = dispatch.Receiver_VAT_Id;

            SenderDispatch senderDispatch = new SenderDispatch();

            if (cmrDispatch != null)
            {
                senderDispatch.Sender_Address = cmrDispatch.Sender_Address;
                senderDispatch.Sender_Email   = cmrDispatch.Sender_Email;
                senderDispatch.Sender_Name    = cmrDispatch.Sender_Name;
                senderDispatch.Sender_VAT_Id  = cmrDispatch.Sender_VAT_Id;
            }

            result.Id = dispatch.Id;
            result.Dispatch_Number      = dispatch.Dispatch_Number;
            result.Creation_Date        = dispatch.Creation_Date == null ? string.Empty : dispatch.Creation_Date.Value.ToString("dd-MM-yyyy");
            result.Car_Id               = dispatch.Car_Id;
            result.Destination          = cmrDispatch == null ? string.Empty : cmrDispatch.Destination;
            result.Carrier              = carrierDispatch;
            result.Receiver             = receiverDispatch;
            result.Sender               = senderDispatch;
            result.Duty_Doc_Id          = dispatch.Duty_Doc_Id;
            result.ListOfOrderPositions = listOfOrderPositionsDispatchInfoPDF;

            return(result);
        }