Exemplo n.º 1
0
        public async Task <int> PrintDocHeaderAsync(Fatture doc, int row, bool stprice)
        {
            Destinazioni dst = null;
            Agenti       age = null;
            var          cli = await dbcon_.GetAsync <Clienti>(doc.fat_inte);

            if (doc.fat_dest != 0)
            {
                dst = await dbcon_.GetAsync <Destinazioni>(doc.fat_dest);
            }
            if (doc.fat_age != 0)
            {
                age = await dbcon_.GetAsync <Agenti>(doc.fat_age);
            }

            int    col      = 0;
            int    last_hor = 0;
            string logo     = "";


            IFolder rootFolder = FileSystem.Current.LocalStorage;
            string  path       = rootFolder.Path + "/images/" + "logo.prn";

            IFile file = await rootFolder.CreateFileAsync(path, CreationCollisionOption.OpenIfExists);

            if (file != null)
            {
                logo = await file.ReadAllTextAsync();
            }


            string str = "^XA" +                  // Inizializziamo la stampa
                         "^PW800" +               // Settiamo la Larghezza
                         "^MN" +                  // Settiamo la stampa in continuos mode
                         "^POI" +
                         "^LH0,0";                // Settiamo la posizione Iniziale


            // Settiamo la lunghezza iniziale del modulo
            str = str + $"^LL{_mod_len}";

            if (logo != "")
            {
                str = str + logo;
            }

            col = 0;
            row = 30 * 8;

            // Scriviamo il Tipo di Documento
            string num = "";

            switch (doc.fat_tipo)
            {
            case (int)DocTipo.TIPO_BOL: num = "B O L L A"; break;

            case (int)DocTipo.TIPO_DDT: num = "DOCUMENTO GENERALE DI TRASPORTO"; break;

            case (int)DocTipo.TIPO_BUO: num = "B U O N O  D I  C O N S E G N A"; break;

            case (int)DocTipo.TIPO_ORD: num = "O R D I N E"; break;

            default: num = "FATTURA/NOTA CONSEGNA TENTATA VENDITA D.P.R.472/96 art.1 comma 3"; break;
            }
            str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB784,1,0,R,0^FD{num}^FS";

            // Disegniamo il box
            col      = 0;
            row     += 3 * 8;
            last_hor = row;
            str      = str + $"^FO{col},{row}" + "^GB800,388,2^FS";

            row += 1 * 8;
            col  = 3;
            str  = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDNum. Doc.^FS";

            col = 16 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDData^FS";

            col = 32 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCod.Cli.^FS";

            col = 42 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCod.Age.^FS";

            col = 52 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDTarga^FS";

            col = 73 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDTelefono^FS";


            // Tracciamo le linee Verticali
            col = 15 * 8;
            str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS";

            col = 31 * 8;
            str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS";

            col = 41 * 8;
            str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS";

            col = 51 * 8;
            str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS";

            col = 71 * 8;
            str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS";


            row += 3 * 8;
            col  = 1;
            num  = string.Format("{0:#,#}/{1}", RsaUtils.GetShowedNumDoc(doc.fat_n_doc), RsaUtils.GetRegistroFromStoredNumDoc(doc.fat_n_doc));
            str  = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{14 * 8},1,0,R,0^FD{num}^FS";

            col = 16 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{14 * 8},1,0,C,0^FD{doc.fat_d_doc:dd/MM/yyy}^FS";

            col = 32 * 8;
            num = string.Format("{0:#}", doc.fat_inte);
            str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FB{8 * 8},1,0,R,0^FD{num}^FS";

            col = 42 * 8;
            num = string.Format("{0:#}", doc.fat_age);
            str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FB{8 * 8},1,0,R,0^FD{num}^FS";

            col = 52 * 8;
            if (age != null)
            {
                str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FB{18 * 8},1,0,L,0^FD{age.age_targa.Trim()}^FS";
            }

            col = 73 * 8;
            if (age != null)
            {
                str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{age.age_targa.Trim()}^FS";
            }

            // Tracciamo la linea orizzontale
            col      = 0;
            row     += 3 * 8;
            last_hor = row;
            str      = str + $"^FO{col},{row}" + $"^GB800,1,2^FS";

            // Intestazione Cliente
            row += 1 * 8;
            col  = 1 * 8;
            str  = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCliente / Cessionario^FS";

            col = 80 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{18 * 8},1,0,R,0^FD{_codcli}^FS";

            row += 4 * 8;
            col  = 1 * 8;
            str  = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{cli.cli_rag_soc1.Trim()}^FS";

            row += 3 * 8;
            str  = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{cli.cli_rag_soc2.Trim()}^FS";

            row += 3 * 8;
            str  = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{cli.cli_indirizzo.Trim()}^FS";

            row += 3 * 8;
            num  = string.Format("{0} {1} {2}", cli.cli_cap, cli.cli_citta, cli.cli_prov);
            str  = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{num.Trim()}^FS";

            row += 3 * 8;
            num  = "";
            if (!string.IsNullOrWhiteSpace(cli.cli_piva))
            {
                num = $"P.IVA {cli.cli_piva}";
            }
            num = num + "       ";
            if (!string.IsNullOrWhiteSpace(cli.cli_codfis))
            {
                num = num + $"Cod. Fiscale {cli.cli_codfis}";
            }
            str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{num.Trim()}^FS";

            // Tracciamo la linea orizzontale
            col      = 0;
            row     += 3 * 8;
            last_hor = row;
            str      = str + $"^FO{col},{row}" + $"^GB800,1,2^FS";


            // Intestazione Destinazione
            row += 1 * 8;
            col  = 1 * 8;
            str  = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDDestinatario e Luogo di Consegna (se diverso dal cessionario) ^FS";

            col = 80 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{18 * 8},1,0,R,0^FD{_coddst}^FS";

            col  = 1 * 8;
            row += 4 * 8;
            if (dst != null)
            {
                str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{dst.dst_rag_soc1.Trim()}^FS";
            }

            row += 3 * 8;
            if (dst != null)
            {
                str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{dst.dst_rag_soc2.Trim()}^FS";
            }

            row += 3 * 8;
            if (dst != null)
            {
                str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{dst.dst_indirizzo.Trim()}^FS";
            }

            row += 3 * 8;
            if (dst != null)
            {
                num = string.Format("{0} {1} {2}", dst.dst_cap, dst.dst_citta, dst.dst_prov);
                str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{num.Trim()}^FS";
            }

            // Tracciamo la linea orizzontale
            col      = 0;
            row     += 3 * 8;
            last_hor = row;
            str      = str + $"^FO{col},{row}" + $"^GB800,1,2^FS";

            col  = 1 * 8;
            row += 1 * 8;

            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCodice^FS";

            col = 15 * 8;
            str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDDescrizione^FS";

            if (stprice)
            {
                col = 30 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDU.M.^FS";

                col = 43 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDQuantita'^FS";

                col = 58 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDPrezzo^FS";

                col = 70 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDSconti^FS";

                col = 83 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDTotale^FS";

                col = 92 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCod.Iva^FS";
            }
            else
            {
                col = 77 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDU.M.^FS";

                col = 92 * 8;
                str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDQuantita'^FS";
            }

            //str = str + "^XZ";
            var t = new UTF8Encoding().GetBytes(str);

            _con.Write(t);

            PostPrintCheckStatus();
            row += 3;
            return(82 * 8);
        }