var table ,  block = $(".content-wrapper").parent();
    var HTML_VIEW_PAY = '';
    var print_page =  `
                        <script>
                          window.print();
                          window.onload = function() { window.print(); }
                        </script>
                        `;
   var table_invoice     =`
                            <html>

                              <head>
                                  
                                  <meta charset="utf-8">
                                  <meta http-equiv="X-UA-Compatible" content="IE=edge">
                                  <meta name="viewport" content="width=device-width, initial-scale=1">
                                  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
                                  <style>
                                      <!--
                                      /* Font Definitions */
                                      
                                      @font-face {
                                          font-family: "Cambria Math";
                                          panose-1: 2 4 5 3 5 4 6 3 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: Calibri;
                                          panose-1: 2 15 5 2 2 2 4 3 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: "Calibri Light";
                                          panose-1: 2 15 3 2 2 2 4 3 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: "Century Gothic";
                                          panose-1: 2 11 5 2 2 2 2 2 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: "Sakkal Majalla";
                                          panose-1: 2 0 0 0 0 0 0 0 0 0;
                                      }
                                      /* Style Definitions */
                                      
                                      p.MsoNormal,
                                      li.MsoNormal,
                                      div.MsoNormal {
                                          margin-top: 0in;
                                          margin-right: 0in;
                                          margin-bottom: 8.0pt;
                                          margin-left: 0in;
                                          line-height: 105%;
                                          font-size: 11.0pt;
                                          font-family: "Calibri", sans-serif;
                                      }
                                      
                                      h2 {
                                          mso-style-link: "Heading 2 Char";
                                          margin: 0in;
                                          margin-bottom: .0001pt;
                                          page-break-after: avoid;
                                          font-size: 8.0pt;
                                          font-family: "Calibri Light", sans-serif;
                                          color: #262626;
                                          font-weight: normal;
                                      }
                                      
                                      p.MsoHeader,
                                      li.MsoHeader,
                                      div.MsoHeader {
                                          mso-style-link: "Header Char";
                                          margin: 0in;
                                          margin-bottom: .0001pt;
                                          font-size: 8.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #262626;
                                      }
                                      
                                      a:link,
                                      span.MsoHyperlink {
                                          color: blue;
                                          text-decoration: underline;
                                      }
                                      
                                      a:visited,
                                      span.MsoHyperlinkFollowed {
                                          color: purple;
                                          text-decoration: underline;
                                      }
                                      
                                      span.Heading2Char {
                                          mso-style-name: "Heading 2 Char";
                                          mso-style-link: "Heading 2";
                                          font-family: "Calibri Light", sans-serif;
                                          color: #262626;
                                      }
                                      
                                      p.msonormal0,
                                      li.msonormal0,
                                      div.msonormal0 {
                                          mso-style-name: msonormal;
                                          margin-right: 0in;
                                          margin-left: 0in;
                                          font-size: 12.0pt;
                                          font-family: "Times New Roman", serif;
                                      }
                                      
                                      span.HeaderChar {
                                          mso-style-name: "Header Char";
                                          mso-style-link: Header;
                                          font-family: "Calibri", sans-serif;
                                          color: #262626;
                                      }
                                      
                                      p.msopapdefault,
                                      li.msopapdefault,
                                      div.msopapdefault {
                                          mso-style-name: msopapdefault;
                                          margin-right: 0in;
                                          margin-bottom: 8.0pt;
                                          margin-left: 0in;
                                          line-height: 105%;
                                          font-size: 12.0pt;
                                          font-family: "Times New Roman", serif;
                                      }
                                      
                                      p.msochpdefault,
                                      li.msochpdefault,
                                      div.msochpdefault {
                                          mso-style-name: msochpdefault;
                                          margin-right: 0in;
                                          margin-left: 0in;
                                          font-size: 10.0pt;
                                          font-family: "Times New Roman", serif;
                                      }
                                      
                                      p.Slogan,
                                      li.Slogan,
                                      div.Slogan {
                                          mso-style-name: Slogan;
                                          margin-top: 0in;
                                          margin-right: 0in;
                                          margin-bottom: 3.0pt;
                                          margin-left: 0in;
                                          font-size: 7.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #A6A6A6;
                                          letter-spacing: .2pt;
                                          font-style: italic;
                                      }
                                      
                                      p.ContactInfo,
                                      li.ContactInfo,
                                      div.ContactInfo {
                                          mso-style-name: "Contact Info";
                                          margin-top: 26.0pt;
                                          margin-right: 0in;
                                          margin-bottom: 0in;
                                          margin-left: 0in;
                                          margin-bottom: .0001pt;
                                          text-align: center;
                                          font-size: 8.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #A6A6A6;
                                      }
                                      
                                      p.ThankYou,
                                      li.ThankYou,
                                      div.ThankYou {
                                          mso-style-name: "Thank You";
                                          margin: 0in;
                                          margin-bottom: .0001pt;
                                          text-align: center;
                                          font-size: 9.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #262626;
                                          font-weight: bold;
                                          font-style: italic;
                                      }
                                      
                                      span.companyphones {
                                          mso-style-name: company_phones;
                                      }
                                      
                                      span.companyemail {
                                          mso-style-name: company_email;
                                      }
                                      
                                      span.invoiceno {
                                          mso-style-name: invoice_no;
                                      }
                                      
                                      span.invoicedate {
                                          mso-style-name: invoice_date;
                                      }
                                      
                                      span.deliverystatus {
                                          mso-style-name: delivery_status;
                                      }
                                      
                                      span.destination {
                                          mso-style-name: destination;
                                      }
                                      
                                      .MsoChpDefault {
                                          font-size: 10.0pt;
                                      }
                                      
                                      @page WordSection1 {
                                          size: 595.3pt 841.9pt;
                                          margin: .5in .5in .5in .5in;
                                      }
                                      
                                      div.WordSection1 {
                                          page: WordSection1;
                                      }
                                      
                                      -->
                                  </style>
                                  <script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
                              </head>

                              <script>

                              COMPANY_ADDRESS = '`+COMPANY_ADDRESS+`';
                              COMPANY_LOGO = '`+COMPANY_LOGO+`';
                              COMPANY_NAME = '`+COMPANY_NAME+`';
                              COMPANY_PHONE = '`+COMPANY_PHONE+`';
                              COMPANY_EMAIL = '`+COMPANY_EMAIL+`';

                              </script>

                              <body lang=EN-US link=blue vlink=purple>

                                  <div class=WordSection1>

                                      <div align=center>
                              `;

   
  
    


    function show_summary(itm,cust_name,phone, email,address,printing=null){

          var headers           ='';
          var attach            = "";
          var attach_other      = "";
          var footers           ="";
          var customer_details  = "";
          var print_attach      = "";
          var total_pay         = "";
          var show_page         = 1;
          var titels            = '';

          

          $.ajax({
                url : 'models/crul_account_statement.php',
                type : 'POST',
                data : {type:'show_invoices_summary', id : itm},
                dataType : 'json',
                success : function(response) {
                    console.log(response)
                  if(response.invoice.length > 0){

                      
                      titels = Translation(' - جميع الوصولات');
                      
                       headers =`

                                  <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=734 style='width:550.5pt;border-collapse:collapse'>
                                    <tr style='height:.25in'>
                                        <td width=264 nowrap colspan=3 style='width:2.75in;border:none;border-bottom:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                            <p class=Slogan style='line-height:105%'><span style='font-family:"Century Gothic",sans-serif'>
                                            <img   width=86 height=77 src="`+COMPANY_LOGO+`">
                                            </p>
                                            <p class=Slogan style='line-height:105%'>
                                                <b>
                                                    <span style='font-size:9.0pt; line-height:105%;font-family:"Century Gothic",sans-serif'>
                                                    `+Translation('Oscar Company')+`
                                                    </span>
                                                </b>
                                            </p>
                                            
                                            <br>
                                        </td>
                                        <td width=409 colspan=11 style='width:307.0pt;border:none;border-bottom:solid windowtext 1.0pt; padding:0in 0in 0in 0in;height:.25in'>
                                            <p class=MsoNormal align=center style='text-align:center'>
                                                <span style='font-size:36.0pt;line-height:105%;font-family:"Century Gothic", sans-serif; color:#A6A6A6'>
                                                ACCOUNT STATEMENT
                                                </span>
                                            </p>
                                        </td>
                                        <td width=60 nowrap style='width:45.15pt;border:none;border-bottom:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                            <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt; text-align:right;direction:rtl;unicode-bidi:embed'>
                                                <span style=' position:relative;top:0px;z-index:-1895822336'>
                                                <span dir=LTR><img width=31  height=62 src="image/sys/image005.gif"></span>
                                            </p>
                                        </td>
                                    </tr>
                                    
                                    `;
                        
                        
                       customer_details = `


                                          <tr style='height:19.25pt'>
                                              <td width=156 nowrap colspan=2 rowspan=4 style='width:117.0pt;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                                      <b>`+Translation('Client Details')+`</b>
                                                  </p>
                                              </td>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;  height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                      `+Translation('Customer:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=9 valign=top style='width:243.0pt;border:none;  border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+cust_name+`
                                                  </p>
                                              </td>
                                              <td width=146 colspan=3 rowspan=4 style='width:109.15pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 0in 0in 0in;height:19.25pt'>
                                                  <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal;direction:rtl;unicode-bidi:embed'>
                                                      <b>
                                                          <span  lang=AR-IQ style='color:black'>
                                                          `+Translation('تفاصيل الزبون')+`
                                                          </span>
                                                      </b>
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('C.Company')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=9 valign=top style='width:243.0pt;border:none; border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                      <span dir=LTR>`+email+`</span>
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('Address:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=9 valign=top style='width:243.0pt;border:none;  border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+address+`
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('Phone No.:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=9 valign=top style='width:243.0pt;border:none; border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+phone+`
                                                  </p>
                                              </td>
                                          </tr>
                                            `;


                     attach =  `
                                    <tr style='height:26.0pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Item No.')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                      <td width=84 nowrap style='width:63.0pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b>
                                                  <span style='color:black'>`+Translation('Voucher #')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                      <td width=90 nowrap colspan=5 style='width:100.5pt;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Date')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=72 nowrap colspan=4 style='width:1.75in;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Transaction')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                      <td width=78 style='width:1.75in;border:solid windowtext 1.0pt;border-left:  none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Debits')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                      <td width=80 nowrap style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:green'>`+Translation('Credits')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=66 nowrap colspan=2 style='width:49.25pt;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Notes')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                  </tr>


                                  `;
                     
                      // show sell item details   
                      var sum_total_invoice   = 0;
                      var sum_total_payment   = 0;
                      var sum_total_discount  = 0;
                      var sum_total_withdraw  = 0;
                      var sum_total_return    = 0;

                      for(var i=0 ; i < response.invoice.length;i++){

                        // compute totals
                       
                        var tansactions = response.invoice[i].transaction_;
                        var tansactions1 = "";
                        switch (tansactions){

                          case 'Payment':
                            sum_total_payment      = +sum_total_payment + +response.invoice[i].credits;
                            tansactions1 = `<span style="color:#008000">`+tansactions+`</span>`;
                            break;

                          case 'Discount':
                            sum_total_discount      = +sum_total_discount + +response.invoice[i].credits;
                            tansactions1 = `<span style="color:#FF8C00">`+tansactions+`</span>`;
                            
                            break;

                          case 'Invoice':
                            sum_total_invoice      = +sum_total_invoice + +response.invoice[i].debits;
                            tansactions1 = `<span style="color: #DC143C">`+tansactions+`</span>`;
                            break;

                          case 'Withdraw':
                            sum_total_withdraw      = +sum_total_withdraw + +response.invoice[i].debits;
                            tansactions1 = `<span style="color:#4B0082">`+tansactions+`</span>`;
                            break;

                          case 'Return':
                            sum_total_return      = +sum_total_return + +response.invoice[i].debits;
                            tansactions1 = `<span style="color:#4682B4">`+tansactions+`</span>`;
                            break;

                        }
                        
                        

                        attach = attach + `
                                               <tr align="center" style='height:15.0pt'>
                                                  <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      `+(i+1)+`
                                                  </td>
                                                  <td width=84 nowrap style='width:63.0pt;border:none;border-bottom:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                      <span style='color:black' id="product_code">
                                                      `+response.invoice[i].voucher_no+`
                                                      
                                                      </span>
                                                    </p>
                                                  </td>
                                                  <td width=90 colspan=5 style='width:100.5pt;border-top:none;border-left:  solid windowtext 1.0pt;border-bottom:solid windowtext 1.0pt;border-right:  solid black 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <span style='font-size:10.0pt;line-height:105%;font-family:"Times New Roman",serif'>
                                                          `+response.invoice[i].date_+`
                                                      </span>
                                                  </td>
                                                  
                                                  <td width=72 nowrap colspan=4 style='width:1.75in;border-top:none;border-left:  none;border-bottom:solid windowtext 1.0pt;border-right:solid gray 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <span style='font-size:10.0pt; font-weight: bold; line-height:105%;font-family:"Times New Roman",serif'>
                                                          `+tansactions1+`
                                                      </span>
                                                  </td>

                                                  <td width=78 style='width:1.75in;border-top:none;border-left:none;border-bottom: solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:15.0pt'>
                                                      <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal;text-align: right;'>
                                                      <span dir="RTL" style='color:black; font-weight: bold;' id="unit_price">`+currency_format_display(response.invoice[i].debits)+`</span>
                                                      </p>
                                                  </td>
                                                  <td width=80 nowrap style='width:59.9pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;   text-align:right;line-height:normal'>
                                                      <span dir="RTL" style='color:black font-weight: bold;' id="row_price">`+currency_format_display(response.invoice[i].credits)+`</span>
                                                    </p>
                                                  </td>
                                                  <td width=66 nowrap colspan=2 style='width:49.25pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;   text-align:center;line-height:normal'>
                                                      <span style='color:black ' id="notes">`+response.invoice[i].note+`</span>
                                                    </p>
                                                  </td>
                                              </tr>
                                             `;
                        
             
                       
                      } // for i


                      if(printing != null){
                        print_attach = `
                                        <script>
                                          window.print();
                                          window.onload = function() { window.print(); }
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                      

                      var total_amount  = +sum_total_invoice + +sum_total_withdraw;
                      var total_paid    = sum_total_payment - sum_total_return;
                      var total_remain  = total_amount - total_paid - sum_total_discount;

                      
                       footers =`

                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;                  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                            
                                      </td>
                                      <td width=516 colspan=11 valign=top style='width:387.0pt;border-top:none;                border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;       text-align:right;line-height:normal'>
                                              <b>
                                                  <span style='color:black'>`+Translation('Grand Total (USD)')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt; text-align:right;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_invoice">`+currency_format_display(total_amount)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      <td width=66 nowrap colspan=2 style='width:49.25pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=11 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Discount (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(sum_total_discount)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      <td width=66 nowrap colspan=2 style='width:49.25pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=11 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <span style='color:green'>`+Translation('Total Paid (USD)')+`</span> 
                                          </p>
                                      </td>
                                      <td width=80 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_paid">`+currency_format_display(total_paid)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      <td width=66 nowrap colspan=2 style='width:49.25pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=11 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:#862D03'>`+Translation('Balance (Not Paid)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal; text-align: right;'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_remain">`+currency_format_display(total_remain)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      <td width=66 nowrap colspan=2 style='width:49.25pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                  </tr>
                                  
                                  <tr style='height:30.5pt'>
                                      <td width=72 valign=top style='width:.75in;padding:0in 5.4pt 0in 5.4pt;  height:30.5pt'>
                                          <p class=ContactInfo align=left style='text-align:left;line-height:105%'>
                                              <b><span  style='font-size:9.0pt;line-height:105%'>`+Translation('Signed By:')+`</span></b>
                                          </p>
                                      </td>
                                      <td width=662 colspan=14 valign=top style='width:496.15pt;padding:0in 0in 0in 0in;  height:30.5pt'>
                                          
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=15 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ContactInfo style='margin-top:0in;line-height:105%'>
                                              <span style='font-size:9.0pt;line-height:105%;color:#7F7F7F'>
                                              `+Translation('Make all checks payable to Oscar Company')+`</span>
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=15 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ThankYou style='line-height:105%'>
                                          `+Translation('Thank you for your business!')+`
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=15 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ContactInfo style='margin-top:12.0pt;line-height:105%'>
                                              <span lang=AR-KW dir=RTL style='font-size:10.0pt;line-height:105%;font-family:"Sakkal Majalla"; color:#7F7F7F'>
                                              `+Translation('شارع ١٠٠م محلة نازناز, مقابل مطار أربيل الدولي, أربيل, عراق')+`
                                              </span>
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:.25in'>
                                      <td width=294 nowrap colspan=6 style='width:120.5pt;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                          
                                            <span dir=LTR class="company_phones">`+COMPANY_PHONE+`</span></span></b></p>

                                          </p>
                                      </td>
                                      <td width=144 nowrap colspan=3 style='width:.5in;padding:0in 5.4pt 0in 5.4pt; height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                              <span style='color:black; text-decoration:none'>`+Translation('www.oscar.co')+`</span>
                                          </p>
                                      </td>
                                      <td width=296 nowrap colspan=6 style='width:221.65pt;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                              <span dir=LTR class="company_email">`+COMPANY_EMAIL+`</span> </span></p>
                                             

                                          </p>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width=72 style='width:.75in;padding:0in 0in 0in 0in'></td>
                                      <td width=84 style='width:63.0pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:81.0pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:22.5pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 colspan=2 style='width:64.95pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:43.05pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:22.2pt;padding:0in 0in 0in 0in'></td>
                                      <td width=25 colspan=2 style='width:18.75pt;padding:0in 0in 0in 0in'></td>
                                      <td width=60 style='width:13.05pt;padding:0in 0in 0in 0in'></td>
                                      <td width=78 style='width:58.5pt;padding:0in 0in 0in 0in'></td>
                                      <td width=80 style='width:59.9pt;padding:0in 0in 0in 0in'></td>
                                      <td width=5 style='width:4.1pt;padding:0in 0in 0in 0in'></td>
                                      <td width=60 style='width:45.15pt;padding:0in 0in 0in 0in'></td>
                                  </tr>
                                  <tr height=0>
                                      <td width=72 style='border:none'></td>
                                      <td width=84 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=15 style='border:none'></td>
                                      <td width=15 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=12 style='border:none'></td>
                                      <td width=13 style='border:none'></td>
                                      <td width=60 style='border:none'></td>
                                      <td width=78 style='border:none'></td>
                                      <td width=80 style='border:none'></td>
                                      <td width=5 style='border:none'></td>
                                      <td width=60 style='border:none'></td>
                                  </tr>
                              </table>

                          </div>

                          

                      </div>

                  </body>

                  
                     `+print_attach+`
                    </html>`;

                  }else{
                    show_page = 0;
                    
                  }    

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);

                      HTML_VIEW_PAY = table_invoice + headers + customer_details + attach + attach_other + footers;
                       //  me.data('requestRunning', false);
                     if(show_page==1){
                        // $("#invoice_show").html(HTML_VIEW_PAY);
                        // $("#inv_numb").val(itm);

                        // $('#show_payments_modal').modal('toggle');

                        window.open().document.write(HTML_VIEW_PAY);

                     }else{
                      noty({
                            width: 200,
                            text: Translation('لا توجد وصولات بيع لهذا النوع'),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 2000,
                            layout: 'topRight',
                      });
                     }
                       
                      
                     
                        // window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }






    


    function load_all_invoices(itm,cust_name,phone, email,address,printing=null){

          var headers           = '';
          var attach            = "";
          var attach_other      = "";
          var footers           = "";
          var customer_details  = "";
          var print_attach      = "";
          var total_pay         = "";
          var show_page         = 1;
          var titels            = '';

          

          $.ajax({
                url : 'models/crul_account_statement.php',
                type : 'POST',
                data : {type:'load_all_invoices', id : itm},
                dataType : 'json',
                success : function(response) {
                    console.log(response)
                  if(response.invoice.length > 0){

                      
                      titels = Translation(' - جميع الوصولات');
                      
                       headers =`

                                  <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=734 style='width:550.5pt;border-collapse:collapse'>
                                    <tr style='height:.25in'>
                                        <td width=264 nowrap colspan=4 style='width:2.75in;border:none;border-bottom:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                            <p class=Slogan style='line-height:105%'><span style='font-family:"Century Gothic",sans-serif'>
                                            <img   width=86 height=77 src="`+COMPANY_LOGO+`">
                                            </p>
                                            <p class=Slogan style='line-height:105%'>
                                                <b>
                                                    <span style='font-size:9.0pt; line-height:105%;font-family:"Century Gothic",sans-serif'>
                                                    `+(COMPANY_NAME)+`
                                                    </span>
                                                </b>
                                            </p>
                                            
                                            <br>
                                        </td>
                                        <td width=409 colspan=11 style='width:307.0pt;border:none;border-bottom:solid windowtext 1.0pt; padding:0in 0in 0in 0in;height:.25in'>
                                            <p class=MsoNormal align=center style='text-align:center'>
                                                <span style='font-size:36.0pt;line-height:105%;font-family:"Century Gothic", sans-serif; color:#A6A6A6'>
                                                Account Statement Details
                                                </span>
                                            </p>
                                        </td>
                                        <td width=60 nowrap style='width:45.15pt;border:none;border-bottom:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                            <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt; text-align:right;direction:rtl;unicode-bidi:embed'>
                                                <span style=' position:relative;top:0px;z-index:-1895822336'>
                                                <span dir=LTR><img width=31  height=62 src="image/sys/image005.gif"></span>
                                            </p>
                                        </td>
                                    </tr>
                                    
                                    `;
                        
                        
                       customer_details = `


                                          <tr style='height:19.25pt'>
                                              <td width=156 nowrap colspan=2 rowspan=4 style='width:117.0pt;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                                      <b>`+Translation('Client Details')+`</b>
                                                  </p>
                                              </td>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;  height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                      `+Translation('Customer:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none;  border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+cust_name+`
                                                  </p>
                                              </td>
                                              <td width=146 colspan=3 rowspan=4 style='width:109.15pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 0in 0in 0in;height:19.25pt'>
                                                  <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal;direction:rtl;unicode-bidi:embed'>
                                                      <b>
                                                          <span  lang=AR-IQ style='color:black'>
                                                          `+Translation('تفاصيل الزبون')+`
                                                          </span>
                                                      </b>
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('C.Company')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none; border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                      <span dir=LTR>`+email+`</span>
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('Address:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none;  border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+address+`
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('Phone No.:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none; border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+phone+`
                                                  </p>
                                              </td>
                                          </tr>
                                            `;


                     attach =  `
                                    <tr style='height:26.0pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Item No.')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                      <td width=84 nowrap style='width:63.0pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b>
                                                  <span style='color:black'>`+Translation('Order #')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                      <td width=90 nowrap  style='width:100.5pt;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Author')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=90 nowrap colspan=5 style='width:100.5pt;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Date')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=72 nowrap colspan=5 style='width:1.75in;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Total Price')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                     <!-- <td width=78 style='width:1.75in;border:solid windowtext 1.0pt;border-left:  none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Total Payment')+`<sup>2</sup></span>
                                              </b>
                                          </p>
                                      </td> -->
                                      <td width=80 nowrap style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:green'>`+Translation('Total Payment')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=66 nowrap colspan=2 style='width:49.25pt;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Notes')+`</span>
                                              </b>
                                          </p>
                                      </td>
                                  </tr>


                                  `;
                     
                      // show sell item details   
                      var sum_total_area    = 0;
                      var sum_total_tac     = 0;
                      

                      for(var i=0 ; i < response.invoice.length;i++){

                       

                        attach = attach + `
                                               <tr align="center" style='height:15.0pt'>
                                                  <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      `+(i+1)+`
                                                  </td>
                                                  <td width=84 nowrap style='width:63.0pt;border:none;border-bottom:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                      <span style='color:black' id="product_code">
                                                      

                                                      <a href="#" class='text-orange-400' onclick="show_invoice(`+response.invoice[i].id+`)" data-popup='tooltip' data-original-title='`+Translation('عرض وصل البيع')+`'>
                                                          <i class='icon-calculator'></i> `+response.invoice[i].voucher_no+`
                                                      </a>
                                                      
                                                      </span>
                                                    </p>
                                                  </td>
                                                  <td width=90  style='width:100.5pt;border-top:none;border-left:  solid windowtext 1.0pt;border-bottom:solid windowtext 1.0pt;border-right:  solid black 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <span style='font-size:10.0pt;line-height:105%;font-family:"Times New Roman",serif'>
                                                          `+response.invoice[i].author+`
                                                      </span>
                                                  </td>
                                                  <td width=90 colspan=5 style='width:100.5pt;border-top:none;border-left:  solid windowtext 1.0pt;border-bottom:solid windowtext 1.0pt;border-right:  solid black 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <span style='font-size:10.0pt;line-height:105%;font-family:"Times New Roman",serif'>
                                                          `+response.invoice[i].date_+`
                                                      </span>
                                                  </td>
                                                  
                                                  <td width=72 nowrap colspan=5 style='width:1.75in;border-top:none;border-left:  none;border-bottom:solid windowtext 1.0pt;border-right:solid gray 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <span style='font-size:10.0pt; font-weight: bold; line-height:105%;font-family:"Times New Roman",serif'>
                                                          `+currency_format_display(response.invoice[i].debits)+`
                                                      </span>
                                                  </td>

                                                  <!--<td width=78 style='width:1.75in;border-top:none;border-left:none;border-bottom: solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:15.0pt'>
                                                      <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal;text-align: right;'>
                                                      <span dir="RTL" style='color:black; font-weight: bold;' id="unit_price">
                                                      `+(response.invoice[i].total_area)+`</span>
                                                      </p>
                                                  </td>-->
                                                  <td width=80 nowrap style='width:59.9pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;   text-align:right;line-height:normal'>
                                                      <span dir="RTL" style='color:black font-weight: bold;' id="row_price">
                                                      `+currency_format_display(response.invoice[i].credits)+`</span>
                                                    </p>
                                                  </td>
                                                  <td width=66 nowrap colspan=2 style='width:49.25pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;   text-align:center;line-height:normal'>
                                                      <span style='color:black ' id="notes">`+response.invoice[i].note+`</span>
                                                    </p>
                                                  </td>
                                              </tr>
                                             `;
                        
             
                       
                      } // for i


                      if(printing != null){
                        print_attach = `
                                        <script>
                                          window.print();
                                          window.onload = function() { window.print(); }
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                      

                      sum_total_area   = sum_total_area.toFixed(3) ;
                      sum_total_tac    = sum_total_tac.toFixed(0) ;
                        
                      
                      footers =`

                                  

                                 

                                   <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;                  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                            
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;                border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;       text-align:right;line-height:normal'>
                                              <b>
                                                  <span style='color:black'>`+Translation('Grand Total (USD)')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt; text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_invoice">`+currency_format_display(response.details[0].total_invoices_price)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>

                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Discount (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(response.details[0].total_payment_discount)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <span style='color:green'>`+Translation('Total Paid (USD)')+`</span> 
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_paid">`+currency_format_display(response.details[0].total_paid)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:#862D03'>`+Translation('Balance (Not Paid)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal; text-align: center;'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_remain">`+currency_format_display(response.details[0].total_remained)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                     
                                  </tr>
                                  
                                  <tr style='height:30.5pt'>
                                      <td width=72 valign=top style='width:.75in;padding:0in 5.4pt 0in 5.4pt;  height:30.5pt'>
                                          <p class=ContactInfo align=left style='text-align:left;line-height:105%'>
                                              <b><span  style='font-size:9.0pt;line-height:105%'>`+Translation('Signed By:')+`</span></b>
                                          </p>
                                      </td>
                                      <td width=662 colspan=15 valign=top style='width:496.15pt;padding:0in 0in 0in 0in;  height:30.5pt'>
                                          
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=16 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ContactInfo style='margin-top:0in;line-height:105%'>
                                              <span style='font-size:9.0pt;line-height:105%;color:#7F7F7F'>
                                              `+Translation('Make all checks payable to Oscar Company')+`</span>
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=16 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ThankYou style='line-height:105%'>
                                          `+Translation('Thank you for your business!')+`
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=16 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ContactInfo style='margin-top:12.0pt;line-height:105%'>
                                              <span lang=AR-KW dir=RTL style='font-size:10.0pt;line-height:105%;font-family:"Sakkal Majalla"; color:#7F7F7F'>
                                              `+COMPANY_ADDRESS+`
                                              </span>
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:.25in'>
                                      <td width=294 nowrap colspan=6 style='width:120.5pt;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                          
                                            <span dir=LTR class="company_phones">`+COMPANY_PHONE+`</span></span></b></p>

                                          </p>
                                      </td>
                                      <td width=144 nowrap colspan=4 style='width:.5in;padding:0in 5.4pt 0in 5.4pt; height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                              <span style='color:black; text-decoration:none'>`+Translation('www.oscar.co')+`</span>
                                          </p>
                                      </td>
                                      <td width=296 nowrap colspan=6 style='width:221.65pt;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                              <span dir=LTR class="company_email">`+COMPANY_EMAIL+`</span> </span></p>
                                             

                                          </p>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width=72 style='width:.75in;padding:0in 0in 0in 0in'></td>
                                      <td width=84 style='width:63.0pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:81.0pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:22.5pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 colspan=2 style='width:64.95pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:43.05pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:22.2pt;padding:0in 0in 0in 0in'></td>
                                      <td width=25 colspan=2 style='width:18.75pt;padding:0in 0in 0in 0in'></td>
                                      <td width=60 style='width:13.05pt;padding:0in 0in 0in 0in'></td>
                                      <td width=78 style='width:58.5pt;padding:0in 0in 0in 0in'></td>
                                      <td width=80 style='width:59.9pt;padding:0in 0in 0in 0in'></td>
                                      <td width=5 style='width:4.1pt;padding:0in 0in 0in 0in'></td>
                                      <td width=60 style='width:45.15pt;padding:0in 0in 0in 0in'></td>
                                  </tr>
                                  <tr height=0>
                                      <td width=72 style='border:none'></td>
                                      <td width=84 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=15 style='border:none'></td>
                                      <td width=15 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=12 style='border:none'></td>
                                      <td width=13 style='border:none'></td>
                                      <td width=60 style='border:none'></td>
                                      <td width=78 style='border:none'></td>
                                      <td width=80 style='border:none'></td>
                                      <td width=5 style='border:none'></td>
                                      <td width=60 style='border:none'></td>
                                  </tr>
                              </table>

                          </div>

                          

                      </div>

                  </body>

                  <script >
                 
                    var Keyword_Array_Js    = '';

                    function Translation(msg){

                      var translated_msg  = msg;
                      if(msg !=null && msg != undefined && msg !=''){
                        var len_array   = Keyword_Array_Js.length;
                          for (var j = 0; j < len_array; ++j) {
                            if(msg.trim() == Keyword_Array_Js[j].keyword){

                              var Translated_key = Keyword_Array_Js[j].translated_keyword;
                              if(Translated_key ==null || Translated_key == ''){
                                Translated_key = Keyword_Array_Js[j].keyword
                              }
                              return Translated_key;
                            }
                          }
                      }
                      
                      return translated_msg;
                    }
                    
                  </script>

                  <script type="text/javascript" src="controllers/invoice_temp.js?`+Math.random()+`"></script>
                  <script type="text/javascript" src="controllers/general_functions.js?`+Math.random()+`"></script>
                  
                    `+print_attach+`
                  </html>`;

                  }else{
                    show_page = 0;
                    
                  }    

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);

                      HTML_VIEW_PAY = table_invoice + headers + customer_details + attach + attach_other + footers;
                       //  me.data('requestRunning', false);
                     if(show_page==1){
                        // $("#invoice_show").html(HTML_VIEW_PAY);
                        // $("#inv_numb").val(itm);

                        // $('#show_payments_modal').modal('toggle');

                        window.open().document.write(HTML_VIEW_PAY);

                     }else{
                      noty({
                            width: 200,
                            text: Translation('لا توجد وصولات بيع لهذا النوع'),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 2000,
                            layout: 'topRight',
                      });
                     }
                       
                      
                     
                        // window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }


     function load_all_invoices_full_detail1(itm,cust_name,phone, email,address,printing=null){

          var headers           = '';
          var attach            = "";
          var attach1           = "";
          var attach_other      = "";
          var footers           = "";
          var customer_details  = "";
          var print_attach      = "";
          var total_pay         = "";
          var show_page         = 1;
          var titels            = '';
          
          var all_invoices      = '';

          var total_invoice     = 0;
          var total_paid        = 0;
          var total_remain      = 0;

          var summury           ="";

          $.ajax({
                url : 'models/crul_account_statement.php',
                type : 'POST',
                data : {type:'load_all_invoices_full_detail', id : itm},
                dataType : 'json',
                success : function(response) {
                    
                  if(response.invoice.length > 0){

                       
                      
                      var kk =0;

                      for(var j=0 ; j < response.invoice.length;j++){

                              attach1          = '';
                              headers          = '';
                              footers          = '';
                              customer_details = '';

                              headers =`

                                  <table id="Table_01" width="795" height="796" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                      <td colspan="8">
                                        <img src="images/ProfessionalDent_01.gif" width="794" height="159" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="159" alt="">
                                      </td>
                                    </tr>
                                    <tr>
                                      <td colspan="2" rowspan="3">
                                        <img src="images/ProfessionalDent_02.gif" width="188" height="106" alt=""></td>
                                      <td colspan="2" rowspan="3" style="background-image: url('images/ProfessionalDent_03.gif');">
                                        `+response.invoice1[0].customer_full_name+`<br>
                                         `+response.invoice1[0].customer_phone+`<br>
                                          `+response.invoice1[0].branch_name+`
                                      </td>
                                      <td colspan="2" rowspan="3">
                                        <img src="images/ProfessionalDent_04.gif" width="123" height="106" alt=""></td>
                                      <td colspan="2" style="background-image: url('images/ProfessionalDent_05.gif');">
                                        `+response.invoice1[0].invoice_number+`
                                      </td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="26" alt=""></td>
                                    </tr>

                                    <tr>
                                      <td colspan="2" style="background-image: url('images/ProfessionalDent_06.gif');">
                                         `+response.invoice1[0].invoice_date+`
                                      </td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="31" alt=""></td>
                                    </tr>

                                    <tr>
                                      <td colspan="2" rowspan="2">
                                        <img src="images/ProfessionalDent_07.gif" width="202" height="50" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="49" alt=""></td>
                                    </tr>
                                    <tr>
                                      <td colspan="6" rowspan="2">
                                        <img src="images/ProfessionalDent_08.gif" width="592" height="22" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="1" alt=""></td>
                                    </tr>
                                    <tr>
                                      <td colspan="2">
                                        <img src="images/ProfessionalDent_09.gif" width="202" height="21" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="21" alt=""></td>
                                    </tr>`;
                        
                        

                              customer_details = ``;


                             

                              attach1 =  `
                                            <tr>
                                              <td>
                                                <img src="images/ProfessionalDent_10.gif" width="123" height="74" alt=""></td>
                                              <td colspan="2">
                                                <img src="images/ProfessionalDent_11.gif" width="274" height="74" alt=""></td>
                                              <td colspan="2">
                                                <img src="images/ProfessionalDent_12.gif" width="121" height="74" alt=""></td>
                                              <td>
                                                <img src="images/ProfessionalDent_13.gif" width="74" height="74" alt=""></td>
                                              <td>
                                                <img src="images/ProfessionalDent_14.gif" width="90" height="74" alt=""></td>
                                              <td>
                                                <img src="images/ProfessionalDent_15.png" width="112" height="74" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="1" height="74" alt=""></td>
                                            </tr>

                                            `;
                               
                                // show sell item details       

                          

                            

                              for(var i=0 ; i < response.invoice1.length;i++){                        

                                if(response.invoice1[i].invoice_id == response.invoice[j].id){

                                    kk = i;

                                    attach1 = attach1 + `
                                              <tr style="">
                                                <td style="background-image: url('images/ProfessionalDent_16.gif'); padding-left: 35px;">
                                                  `+(i+1)+`
                                                </td>
                                                <td colspan="2" style="background-image: url('images/ProfessionalDent_17.gif'); text-align:left;">
                                                   `+response.invoice1[i].product_name+`
                                                </td>
                                                <td colspan="2" style="background-image: url('images/ProfessionalDent_18.gif');">
                                                  `+currency_format_display(response.invoice1[i].item_sell_price_per_unit)+`
                                                </td>
                                                <td style="background-image: url('images/ProfessionalDent_19.gif');">
                                                 `+response.invoice1[i].sell_item_quantity+`
                                                </td>
                                                <td style="background-image: url('images/ProfessionalDent_20.gif');">
                                                  `+currency_format_display(response.invoice1[i].sell_actual_discount)+`
                                                </td>
                                                <td style="background-image: url('images/ProfessionalDent_21.gif');">
                                                  `+currency_format_display(response.invoice1[i].row_price)+`
                                                </td>
                                                <td>
                                                  <img src="images/spacer.gif" width="1" height="83" alt="">
                                                </td>
                                              </tr> `;
                        

                                  
                                } // if invoice_id
                                 
                              } // for i

                                
                                total_invoice     = +total_invoice + +(response.invoice1[kk].invoice_total_price_actual);
                                total_paid        = +total_paid + +(response.invoice1[kk].total_paid);
                                total_remain      = +total_remain + +(response.invoice1[kk].total_remained);

                                 footers =`
                                            <tr>
                                              <td colspan="6">
                                                <img src="images/ProfessionalDent_22.gif" width="592" height="84" alt=""></td>
                                              <td colspan="2" style="background-image: url('images/ProfessionalDent_23.gif'); font-size:20px;">
                                                `+currency_format_display(response.invoice1[kk].invoice_total_price_actual)+`
                                              </td>
                                              <td>
                                                <img src="images/spacer.gif" width="1" height="84" alt=""></td>
                                            </tr>

                                            <tr>
                                              <td colspan="8">
                                                <img src="images/ProfessionalDent_24.gif" width="794" height="114" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="1" height="114" alt=""></td>
                                            </tr>
                                            <tr>
                                              <td colspan="8">
                                                <img src="images/ProfessionalDent_25.gif" width="794" height="80" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="1" height="80" alt=""></td>
                                            </tr>
                                            <tr>
                                              <td colspan="8">
                                                <img src="images/ProfessionalDent_26.png" width="794" height="73" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="1" height="73" alt=""></td>
                                            </tr>
                                            <tr>
                                              <td>
                                                <img src="images/spacer.gif" width="123" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="65" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="209" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="72" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="49" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="74" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="90" height="1" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="112" height="1" alt=""></td>
                                              <td></td>
                                            </tr>
                                          </table>`;


                                footers =`

                                           
                                   

                                    <p style="page-break-after: always;">&nbsp;</p>
                                    <p style="page-break-before: always;">&nbsp;</p>`;

                          all_invoices = all_invoices + headers + customer_details + attach1 + footers;
             
                       
                      } // for j


                      if(printing != null){
                        print_attach = `
                                        <script>
                                          window.print();
                                          window.onload = function() { window.print(); }
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                      
                       summury = `<center><table>


                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Grand Total (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(response.details[0].total_invoices_price)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>

                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Discount (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(response.details[0].total_payment_discount)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <span style='color:green'>`+Translation('Total Paid (USD)')+`</span> 
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_paid">`+currency_format_display(response.details[0].total_paid)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:#862D03'>`+Translation('Balance (Not Paid)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal; text-align: center;'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_remain">`+currency_format_display(response.details[0].total_remained)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                     
                                  </tr>
                                  
                                  
                                 
                                 
                              </table></center>`;
                    

                     all_invoices = all_invoices + ` </div>                                   

                                                    </div>
                                                  </body>`+print_attach+`
                                                  </html>';`
                      
     

                  }else{
                    show_page = 0;
                    
                  }    

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);

                      HTML_VIEW_PAY = table_invoice + all_invoices + summury;
                       //  me.data('requestRunning', false);
                     if(show_page!=0){
                       
                        window.open().document.write(HTML_VIEW_PAY);

                     }else{
                      noty({
                            width: 200,
                            text: Translation('لا توجد وصولات بيع لهذا النوع'),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 2000,
                            layout: 'topRight',
                      });
                     }
                       
                      
                     
                        // window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }

    function load_all_invoices_full_detail(itm,cust_name,phone, email,address,printing=null){

          var headers           = '';
          var attach            = "";
          var attach1           = "";
          var attach_other      = "";
          var footers           = "";
          var customer_details  = "";
          var print_attach      = "";
          var total_pay         = "";
          var show_page         = 1;
          var titels            = '';
          
          var all_invoices      = '';

          var total_invoice     = 0;
          var total_paid        = 0;
          var total_remain      = 0;

          var summury           ="";

          $.ajax({
                url : 'models/crul_account_statement.php',
                type : 'POST',
                data : {type:'load_all_invoices_full_detail', id : itm},
                dataType : 'json',
                success : function(response) {
                    
                  if(response.invoice.length > 0){

                       
                      
                      var kk =0;

                      for(var j=0 ; j < response.invoice.length;j++){

                              attach1          = '';
                              headers          = '';
                              footers          = '';
                              customer_details = '';

                              headers =`

                                  <table id="Table_01" width="795" height="796" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                      <td colspan="8">
                                        <img src="images/ProfessionalDent_01.gif" width="794" height="159" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="159" alt="">
                                      </td>
                                    </tr>
                                    <tr>
                                      <td colspan="2" rowspan="3">
                                        <img src="images/ProfessionalDent_02.gif" width="188" height="106" alt=""></td>
                                      <td colspan="2" rowspan="3" style="color: aliceblue;
                                                                         font-size: x-large;
                                                                         font-weight: bold;
                                                                         text-align: center; 
                                                                         background-image: url('images/ProfessionalDent_03.gif');">
                                        `+response.invoice1[j].customer_full_name+`<br>
                                         `+response.invoice1[j].customer_phone+`<br>
                                          `+response.invoice1[j].branch_name+`
                                      </td>
                                      <td colspan="2" rowspan="3">
                                        <img src="images/ProfessionalDent_04.gif" width="123" height="106" alt=""></td>
                                      <td colspan="2" style="font-size: x-large;
                                                              font-weight: bold;
                                                              text-align: center;
                                                              text-transform: uppercase;
                                                              background-image: url('images/ProfessionalDent_05.gif');">
                                        `+response.invoice[j].invoice_number+`
                                      </td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="26" alt=""></td>
                                    </tr>

                                    <tr>
                                      <td colspan="2" style="font-size: x-large;
                                                              font-weight: bold;
                                                              text-align: center;
                                                              text-transform: uppercase;
                                                              background-image: url('images/ProfessionalDent_06.gif');">
                                         `+response.invoice[j].invoice_date+`
                                      </td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="31" alt=""></td>
                                    </tr>

                                    <tr>
                                      <td colspan="2" rowspan="2">
                                        <img src="images/ProfessionalDent_07.gif" width="202" height="50" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="49" alt=""></td>
                                    </tr>
                                    <tr>
                                      <td colspan="6" rowspan="2">
                                        <img src="images/ProfessionalDent_08.gif" width="592" height="22" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="1" alt=""></td>
                                    </tr>
                                    <tr>
                                      <td colspan="2">
                                        <img src="images/ProfessionalDent_09.gif" width="202" height="21" alt=""></td>
                                      <td>
                                        <img src="images/spacer.gif" width="1" height="21" alt=""></td>
                                    </tr>`;
                        
                        

                              customer_details = ``;

                              attach1 =  `
                                            <tr>
                                              <td>
                                                <img src="images/ProfessionalDent_10.gif" width="123" height="74" alt=""></td>
                                              <td colspan="2">
                                                <img src="images/ProfessionalDent_11.gif" width="274" height="74" alt=""></td>
                                              <td colspan="2">
                                                <img src="images/ProfessionalDent_12.gif" width="121" height="74" alt=""></td>
                                              <td>
                                                <img src="images/ProfessionalDent_13.gif" width="74" height="74" alt=""></td>
                                              <td>
                                                <img src="images/ProfessionalDent_14.gif" width="90" height="74" alt=""></td>
                                              <td>
                                                <img src="images/ProfessionalDent_15.png" width="112" height="74" alt=""></td>
                                              <td>
                                                <img src="images/spacer.gif" width="1" height="74" alt=""></td>
                                            </tr>
                                            `;
                               
                                // show sell item details       

                          

                            

                              for(var i=0 ; i < response.invoice1.length;i++){                        

                                if(response.invoice1[i].invoice_id == response.invoice[j].id){

                                    kk = i;
                                    attach1 = attach1 + `
                                                        <tr style="">
                                                          <td style="background-image: url('images/ProfessionalDent_16.gif'); padding-left: 35px;">
                                                            `+(i+1)+`
                                                          </td>
                                                          <td colspan="2" style="background-image: url('images/ProfessionalDent_17.gif'); text-align:left;">
                                                             `+response.invoice1[i].product_name+`
                                                          </td>
                                                          <td colspan="2" style="background-image: url('images/ProfessionalDent_18.gif');">
                                                            `+currency_format_display(response.invoice1[i].item_sell_price_per_unit)+`
                                                          </td>
                                                          <td style="background-image: url('images/ProfessionalDent_19.gif');">
                                                           `+response.invoice1[i].sell_item_quantity+`
                                                          </td>
                                                          <td style="background-image: url('images/ProfessionalDent_20.gif');">
                                                            `+currency_format_display(response.invoice1[i].sell_actual_discount)+`
                                                          </td>
                                                          <td style="background-image: url('images/ProfessionalDent_21.gif');">
                                                            `+currency_format_display(response.invoice1[i].row_price)+`
                                                          </td>
                                                          <td>
                                                            <img src="images/spacer.gif" width="1" height="83" alt="">
                                                          </td>
                                                        </tr>
                                                       `;
                                  
                                } // if invoice_id
                                 
                              } // for i

                                
                                total_invoice     = +total_invoice + +(response.invoice1[kk].invoice_total_price_actual);
                                total_paid        = +total_paid + +(response.invoice1[kk].total_paid);
                                total_remain      = +total_remain + +(response.invoice1[kk].total_remained);

                                footers =`

                                          <tr>
                                            <td colspan="6">
                                              <img src="images/ProfessionalDent_22.gif" width="592" height="84" alt=""></td>
                                            <td colspan="2" style="background-image: url('images/ProfessionalDent_23.gif'); font-size:20px;">
                                              `+currency_format_display(response.invoice1[kk].invoice_total_price_actual)+`
                                            </td>
                                            <td>
                                              <img src="images/spacer.gif" width="1" height="84" alt=""></td>
                                          </tr>

                                          <tr>
                                            <td colspan="8">
                                              <img src="images/ProfessionalDent_24.gif" width="794" height="114" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="1" height="114" alt=""></td>
                                          </tr>
                                          <tr>
                                            <td colspan="8">
                                              <img src="images/ProfessionalDent_25.gif" width="794" height="80" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="1" height="80" alt=""></td>
                                          </tr>
                                          <tr>
                                            <td colspan="8">
                                              <img src="images/ProfessionalDent_26.png" width="794" height="73" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="1" height="73" alt=""></td>
                                          </tr>
                                          <tr>
                                            <td>
                                              <img src="images/spacer.gif" width="123" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="65" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="209" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="72" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="49" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="74" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="90" height="1" alt=""></td>
                                            <td>
                                              <img src="images/spacer.gif" width="112" height="1" alt=""></td>
                                            <td></td>
                                          </tr>
                                        </table>

                                       
                                        <p style="page-break-after: always;">&nbsp;</p>
                                        <p style="page-break-before: always;">&nbsp;</p>`;

                          all_invoices = all_invoices + headers + customer_details + attach1 + footers;
             
                       
                      } // for j


                      if(printing != null){
                        print_attach = `
                                        <script>
                                          window.print();
                                          window.onload = function() { window.print(); }
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                      
                       summury = `<center><table>


                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Grand Total (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(response.details[0].total_invoices_price)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>

                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Discount (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(response.details[0].total_payment_discount)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <span style='color:green'>`+Translation('Total Paid (USD)')+`</span> 
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_paid">`+currency_format_display(response.details[0].total_paid)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:#862D03'>`+Translation('Balance (Not Paid)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal; text-align: center;'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_remain">`+currency_format_display(response.details[0].total_remained)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                     
                                  </tr>
                                  
                                  
                                 
                                 
                              </table></center>`;
                    

                     all_invoices = all_invoices + `
                                                  </body>`+print_attach+`
                                                  </html>';`
                      
     

                  }else{
                    show_page = 0;
                    
                  }    

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);

                      HTML_VIEW_PAY = table_invoice + all_invoices + summury;
                       //  me.data('requestRunning', false);
                     if(show_page!=0){
                       
                        window.open().document.write(HTML_VIEW_PAY);

                     }else{
                      noty({
                            width: 200,
                            text: Translation('لا توجد وصولات بيع لهذا النوع'),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 2000,
                            layout: 'topRight',
                      });
                     }
                       
                      
                     
                        // window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }

    function load_all_invoices_just_totals(itm,cust_name,phone, email,address,printing=null){

          var headers           = '';
          var attach            = "";
          var attach_other      = "";
          var footers           = "";
          var customer_details  = "";
          var print_attach      = "";
          var total_pay         = "";
          var show_page         = 1;
          var titels            = '';

          

          $.ajax({
                url : 'models/crul_account_statement.php',
                type : 'POST',
                data : {type:'load_all_invoices_just_totals', id : itm},
                dataType : 'json',
                success : function(response) {
                    console.log(response)
                  if(response.details.length > 0){

                      
                      titels = Translation(' - جميع الوصولات');
                      
                       headers =`

                                  <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=734 style='width:550.5pt;border-collapse:collapse'>
                                    <tr style='height:.25in'>
                                        <td width=264 nowrap colspan=4 style='width:2.75in;border:none;border-bottom:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                            <p class=Slogan style='line-height:105%'><span style='font-family:"Century Gothic",sans-serif'>
                                            <img   width=86 height=77 src="`+COMPANY_LOGO+`">
                                            </p>
                                            <p class=Slogan style='line-height:105%'>
                                                <b>
                                                    <span style='font-size:9.0pt; line-height:105%;font-family:"Century Gothic",sans-serif'>
                                                    `+Translation('Oscar Company')+`
                                                    </span>
                                                </b>
                                            </p>
                                            
                                            <br>
                                        </td>
                                        <td width=409 colspan=11 style='width:307.0pt;border:none;border-bottom:solid windowtext 1.0pt; padding:0in 0in 0in 0in;height:.25in'>
                                            <p class=MsoNormal align=center style='text-align:center'>
                                                <span style='font-size:36.0pt;line-height:105%;font-family:"Century Gothic", sans-serif; color:#A6A6A6'>
                                                Account Statement Details
                                                </span>
                                            </p>
                                        </td>
                                        <td width=60 nowrap style='width:45.15pt;border:none;border-bottom:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                            <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt; text-align:right;direction:rtl;unicode-bidi:embed'>
                                                <span style=' position:relative;top:0px;z-index:-1895822336'>
                                                <span dir=LTR><img width=31  height=62 src="image/sys/image005.gif"></span>
                                            </p>
                                        </td>
                                    </tr>
                                    
                                    `;
                        
                        
                       customer_details = `


                                          <tr style='height:19.25pt'>
                                              <td width=156 nowrap colspan=2 rowspan=4 style='width:117.0pt;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                                      <b>`+Translation('Client Details')+`</b>
                                                  </p>
                                              </td>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;  height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                      `+Translation('Customer:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none;  border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:19.25pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+cust_name+`
                                                  </p>
                                              </td>
                                              <td width=146 colspan=3 rowspan=4 style='width:109.15pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 0in 0in 0in;height:19.25pt'>
                                                  <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal;direction:rtl;unicode-bidi:embed'>
                                                      <b>
                                                          <span  lang=AR-IQ style='color:black'>
                                                          `+Translation('تفاصيل الزبون')+`
                                                          </span>
                                                      </b>
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('C.Company')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none; border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                      <span dir=LTR>`+email+`</span>
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('Address:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none;  border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+address+`
                                                  </p>
                                              </td>
                                          </tr>
                                          <tr style='height:17.0pt'>
                                              <td width=108 valign=top style='width:81.0pt;padding:0in 5.4pt 0in 5.4pt;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+Translation('Phone No.:')+`
                                                  </p>
                                              </td>
                                              <td width=324 colspan=10 valign=top style='width:243.0pt;border:none; border-right:solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:17.0pt'>
                                                  <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt'>
                                                  `+phone+`
                                                  </p>
                                              </td>
                                          </tr>
                                            `;


                     attach =  ``;
                     
                     


                      if(printing != null){
                        print_attach = `
                                        <script>
                                          window.print();
                                          window.onload = function() { window.print(); }
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                      
    
                      
                      footers =`

                                 


                                   <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;                  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                            
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;                border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;       text-align:right;line-height:normal'>
                                              <b>
                                                  <span style='color:black'>`+Translation('Grand Total (USD)')+`</span> 
                                              </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt; text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_invoice">`+currency_format_display(response.details[0].total_invoices_price)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>

                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:red'>`+Translation('Discount (USD)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 valign=top colspan=3 style='width:59.9pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_discount">`+currency_format_display(response.details[0].total_payment_discount)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <span style='color:green'>`+Translation('Total Paid (USD)')+`</span> 
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_paid">`+currency_format_display(response.details[0].total_paid)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                      
                                  </tr>
                                  <tr style='height:17.1pt'>
                                      <td width=72 nowrap style='width:.75in;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          
                                      </td>
                                      <td width=516 colspan=12 valign=top style='width:387.0pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:17.1pt'>
                                          <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;line-height:normal'>
                                              <b><span style='color:#862D03'>`+Translation('Balance (Not Paid)')+`</span> </b>
                                          </p>
                                      </td>
                                      <td width=80 colspan=3 style='width:59.9pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;  height:17.1pt'>
                                          <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal; text-align: center;'>
                                          <b>
                                            <span dir="RTL" style='color:black' id="total_remain">`+currency_format_display(response.details[0].total_remained)+`</span>
                                          </b>
                                        </p>
                                      </td>
                                     
                                  </tr>
                                  
                                  <tr style='height:30.5pt'>
                                      <td width=72 valign=top style='width:.75in;padding:0in 5.4pt 0in 5.4pt;  height:30.5pt'>
                                          <p class=ContactInfo align=left style='text-align:left;line-height:105%'>
                                              <b><span  style='font-size:9.0pt;line-height:105%'>`+Translation('Signed By:')+`</span></b>
                                          </p>
                                      </td>
                                      <td width=662 colspan=15 valign=top style='width:496.15pt;padding:0in 0in 0in 0in;  height:30.5pt'>
                                          
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=16 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ContactInfo style='margin-top:0in;line-height:105%'>
                                              <span style='font-size:9.0pt;line-height:105%;color:#7F7F7F'>
                                              `+Translation('Make all checks payable to Oscar Company')+`</span>
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=16 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ThankYou style='line-height:105%'>
                                          `+Translation('Thank you for your business!')+`
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:6.0pt'>
                                      <td width=734 colspan=16 valign=top style='width:550.15pt;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                          <p class=ContactInfo style='margin-top:12.0pt;line-height:105%'>
                                              <span lang=AR-KW dir=RTL style='font-size:10.0pt;line-height:105%;font-family:"Sakkal Majalla"; color:#7F7F7F'>
                                              `+COMPANY_ADDRESS+`
                                              </span>
                                          </p>
                                      </td>
                                  </tr>
                                  <tr style='height:.25in'>
                                      <td width=294 nowrap colspan=6 style='width:120.5pt;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                          
                                            <span dir=LTR class="company_phones">`+COMPANY_PHONE+`</span></span></b></p>

                                          </p>
                                      </td>
                                      <td width=144 nowrap colspan=4 style='width:.5in;padding:0in 5.4pt 0in 5.4pt; height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                              <span style='color:black; text-decoration:none'>`+Translation('www.oscar.co')+`</span>
                                          </p>
                                      </td>
                                      <td width=296 nowrap colspan=6 style='width:221.65pt;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                              <span dir=LTR class="company_email">`+COMPANY_EMAIL+`</span> </span></p>
                                             

                                          </p>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width=72 style='width:.75in;padding:0in 0in 0in 0in'></td>
                                      <td width=84 style='width:63.0pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:81.0pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:22.5pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 colspan=2 style='width:64.95pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:43.05pt;padding:0in 0in 0in 0in'></td>
                                      <td width=30 style='width:22.2pt;padding:0in 0in 0in 0in'></td>
                                      <td width=25 colspan=2 style='width:18.75pt;padding:0in 0in 0in 0in'></td>
                                      <td width=60 style='width:13.05pt;padding:0in 0in 0in 0in'></td>
                                      <td width=78 style='width:58.5pt;padding:0in 0in 0in 0in'></td>
                                      <td width=80 style='width:59.9pt;padding:0in 0in 0in 0in'></td>
                                      <td width=5 style='width:4.1pt;padding:0in 0in 0in 0in'></td>
                                      <td width=60 style='width:45.15pt;padding:0in 0in 0in 0in'></td>
                                  </tr>
                                  <tr height=0>
                                      <td width=72 style='border:none'></td>
                                      <td width=84 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=15 style='border:none'></td>
                                      <td width=15 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=30 style='border:none'></td>
                                      <td width=12 style='border:none'></td>
                                      <td width=13 style='border:none'></td>
                                      <td width=60 style='border:none'></td>
                                      <td width=78 style='border:none'></td>
                                      <td width=80 style='border:none'></td>
                                      <td width=5 style='border:none'></td>
                                      <td width=60 style='border:none'></td>
                                  </tr>
                              </table>

                          </div>

                          

                      </div>

                  </body>

                  
                     `+print_attach+`
                    </html>`;

                  }else{
                    show_page = 0;
                    
                  }    

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);

                      HTML_VIEW_PAY = table_invoice + headers + customer_details + attach + attach_other + footers;
                       //  me.data('requestRunning', false);
                     if(show_page==1){
                        // $("#invoice_show").html(HTML_VIEW_PAY);
                        // $("#inv_numb").val(itm);

                        // $('#show_payments_modal').modal('toggle');

                        window.open().document.write(HTML_VIEW_PAY);

                     }else{
                      noty({
                            width: 200,
                            text: Translation('لا توجد وصولات بيع لهذا النوع'),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 2000,
                            layout: 'topRight',
                      });
                     }
                       
                      
                     
                        // window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }

    function show_withdraw_summary(itm,typ=null){

          var headers           ='';
          var attach            = "";
          var attach_other      = "";
          var footers           ="";
          var customer_details  = "";
          var print_attach      = "";
          var total_pay         = "";
          var show_page         = 1;
          var titels            = '';

          

          $.ajax({
                url : 'models/crul_account_statement.php',
                type : 'POST',
                data : {type:'show_withdraw_summary', id : itm, typ:typ},
                dataType : 'json',
                success : function(response) {
                    console.log(response)
                  if(response.invoice.length > 0){

                      if(typ == null){
                        titels = Translation(' - جميع الوصولات');
                      }else if(typ == 'raw'){
                        // titels = ' - المواد الخامة';
                        titels = Translation(' - المواد الخامة');

                      }else if(typ == 'm'){
                        // titels = ' - ستائر الجملة';
                        titels = Translation(' - ستائر الجملة');

                      }else if(typ == 's'){
                        // titels = ' - ستائر المفرد';
                        titels = Translation(' - ستائر المفرد');

                      }else if(typ == 'w'){
                        titels = Translation(' - القروض المستلمة');
                      }
                    
                      headers =`

                                    <table  dir=rtl border=1 cellspacing=0 cellpadding=0
                                       style='background:white;border-collapse:collapse;border:none; font-weight:bold;'>
                                       <tr>
                                        <td width=590 colspan=6 style='width:6.15in;border:none;padding:0in 5.4pt 0in 5.4pt'>       
                                          <span style="float: left; font-size: 20px;" id="inv_slogan">`+COMPANY_NAME+`</span>
                                        </td>
                                       </tr>
                                       <tr style='height:9.95pt'>
                                        <td width=295 colspan=3 style='width:221.4pt;' class="table0_td">
                                        <span id="inv_address"> `+Translation(COMPANY_ADDRESS)+` </span>
                                        </td>
                                        <td width=295 colspan=3 rowspan=2 style='width:221.4pt;' class="table0_td">
                                        <span id="inv_logo">  </span>
                                        </td>
                                       </tr>
                                       
                                       <tr style='height:9.95pt'>
                                        <td width=295 colspan=3 style='width:221.4pt;' class="table0_td">
                                        موبايل : <span dir="ltr" id="inv_phone"> `+COMPANY_PHONE+` </span>
                                        <br>
                                        البريد الالكتروني : <span dir="ltr" id="inv_email"> `+COMPANY_EMAIL+` </span>
                                        </td>
                                       </tr>
                                       <tr>
                                        <td width=590 colspan=6 class="table0_td1" style='text-align:center; width:6.15in;border:none;padding:0in 5.4pt 0in 5.4pt'>       
                                          <span style=" font-size: 20px;" id="inv_slogan">`+Translation('كشف حساب ')+titels+`</span>
                                        </td>
                                       </tr>
                                       
                                       
                                       
                                      </table>
                                  
                                          `;
                        
                      customer_details = `

                                            <table  dir=rtl border=1 cellspacing=0 cellpadding=0  width=595 style='width:6.2in;border-collapse:collapse;border:none'>
                                             <tr style='page-break-inside:avoid;' class="td_head">
                                              <td width=307 style='width:3.2in;' class="table1_td">
                                              اسم الزبون
                                              </td>
                                              <td width=144 style='width:1.5in;' class="table1_td">
                                              رقم الهاتف
                                              </td>
                                              <td width=144 style='width:1.5in;' class="table1_td last_td">
                                              العنوان
                                              </td>
                                             </tr>
                                             <tr style='page-break-inside:avoid;' class="td_body">
                                              <td width=307 style='width:3.2in;' class="table1_td1">
                                              <span  id="inv_customer_name"> `+response.invoice[0].customer_full_name+` </span>
                                              </td>
                                              <td width=144 style='width:1.5in;' class="table1_td1">
                                              <span  id="inv_customer_phone"> `+response.invoice[0].customer_phone+` </span>
                                              </td>
                                              <td width=144 style='width:1.5in;' class="table1_td1">
                                              <span  id="inv_customer_address"> `+response.invoice[0].customer_address+` </span>
                                              </td>
                                             </tr>
                                            </table>
                                            <br>
                                            `;

                      attach =  `
                                  <table id="inv_table"  dir=rtl border=1 cellspacing=0 cellpadding=0 width=591 style='width:443.5pt;border-collapse:collapse;border:#000000; '>
                                   <tr style='page-break-inside:avoid;' class="td_head">
                                    <td width=23 style='width:14.4pt;' class="table2_td">
                                    `+Translation('ت')+`
                                    </td>
                                    <td width=81.4 style='width:61.05pt;' class="table2_td">
                                      `+Translation('رقم الوصل')+`
                                    </td>
                                    <td width=81.4 style='width:61.05pt;' class="table2_td">
                                      `+Translation('تاريخ الوصل')+`
                                    </td>
                                    <td width=81.4 style='width:61.05pt;' class="table2_td ">
                                    `+Translation('المبلغ الكلي')+`
                                    </td>
                                    <td width=81.4 style='width:61.05pt;' class="table2_td">
                                    `+Translation('المبلغ المدفوع')+`
                                    </td>
                                    <td width=81.4 style='width:61.05pt;' class="table2_td">
                                   `+Translation('المبلغ الباقي')+` 
                                    </td>
                                    <td width=152 style='width:113.85pt;' class="table2_td last_td">
                                    `+Translation('ملاحظات')+`
                                    </td>
                                    
                                    
                                   </tr>`;
                     
                      // show sell item details   
                      var sum_total_cost      = 0;
                      var sum_total_paid      = 0;
                      var sum_total_remaind   = 0;
                      var sum_total_discount  = 0;

                      for(var i=0 ; i < response.invoice.length;i++){

                        // compute totals
                       
                        

                        sum_total_cost      = response.invoice[i].total_withdraw_price;
                        sum_total_paid      = response.invoice[i].total_paid;
                        sum_total_remaind   = response.invoice[i].total_remained;
                        

                        attach = attach + `
                                                  <tr style='page-break-inside:avoid;' class="td_body">
                                                    <td width=23 style='width:14.4pt;'>
                                                      <span  id="inv_count"> `+(i+1)+` </span>
                                                    </td>
                                                    <td width=81.4 style='width:61.05pt;'>
                                                      <span  id="inv_product"> `+response.invoice[i].capital_withdraw_id+` </span>
                                                    </td>
                                                    <td width=81.4 style='width:61.05pt;'>
                                                      <span  id="inv_quantity"> `+response.invoice[i].withdraw_date+` </span>
                                                    </td>
                                                    <td width=81.4 style='width:61.05pt;' class="last_td">
                                                      <span  id="inv_total_row"> `+currency_format_display(response.invoice[i].withdraw_amount)+`  </span>
                                                    </td>
                                                    <td width=81.4 style='width:61.05pt; font-family:  Times, serif;'>
                                                      <span  id="inv_details"> `+currency_format_display(0)+` </span>
                                                    </td>
                                                    <td width=81.4  style='width:61.05pt;'>
                                                      <span  id="inv_total_length"> `+currency_format_display(0)+`  </span>
                                                    </td>
                                                    <td width=152 style='width:113.85pt;'>
                                                      <span  id="inv_unit_price"> `+(response.invoice[i].withdraw_note)+` </span>
                                                    </td>
                                                    
                                                    
                                                   </tr>
                                                  `;

                       
                       
                      } // for i

                      

                      footers =`
                                 
                                 <tr style='page-break-inside:avoid;height:.1in'>
                                  <td width=517 colspan=6 valign=top style='width:388.0pt;border:none;
                                  border-left:solid #984806 1.0pt;background:white;padding:2.15pt 5.75pt 2.15pt 5.75pt;
                                  height:.1in'>
                                  `+Translation('المبلغ الكلي')+`
                                  </td>
                                  <td width=74 style='width:55.5pt;border-top:none;border-left:solid #984806 1.0pt;
                                  border-bottom:solid #984806 1.0pt;border-right:none;
                                  padding:0pt .1in 0pt .1in;height:.1in'>
                                   `+currency_format_display(sum_total_cost)+`
                                  </td>
                                 </tr>
                                 <tr style='page-break-inside:avoid;height:.1in'>
                                  <td width=517 colspan=6 valign=top style='width:388.0pt;border:none;
                                  border-left:solid #984806 1.0pt;background:white;padding:2.15pt 5.75pt 2.15pt 5.75pt;
                                  height:.1in'>
                                  `+Translation('المبلغ المدفوع')+`
                                  </td>
                                  <td width=74 style='width:55.5pt;border-top:none;border-left:solid #984806 1.0pt;
                                  border-bottom:solid #984806 1.0pt;border-right:none;
                                  padding:0pt .1in 0pt .1in;height:.1in'>
                                  `+currency_format_display(sum_total_paid)+`
                                  </td>
                                 </tr>
                                 <tr style='page-break-inside:avoid;height:.1in'>
                                  <td width=517 colspan=6 valign=top style='width:388.0pt;border:none;
                                  border-left:solid #984806 1.0pt;background:white;padding:2.15pt 5.75pt 2.15pt 5.75pt;
                                  height:.1in'>
                                  `+Translation('المبلغ المتبقي')+`
                                  </td>
                                  <td width=74 style='width:55.5pt;border-top:none;border-left:solid #984806 1.0pt;
                                  border-bottom:solid #984806 1.0pt;border-right:none;
                                  padding:0pt .1in 0pt .1in;height:.1in'>
                                  `+currency_format_display(sum_total_remaind)+`
                                  </td>
                                 </tr>
                                 <tr style='page-break-inside:avoid;height:.3in'>
                                 
                                  <td width=517 colspan=7  style='width:388.0pt;border:none;background:white;
                                    padding:2.15pt 5.75pt 2.15pt 5.75pt;height:.1in'>
                                    <span id="inv_note">`+Translation('ملاحظة')+` : `+''+` </span>
                                  </td>
                                 </tr>
                                 
                                 <tr style='page-break-inside:avoid;height:.1in; background-color: white'>
                                  <td width=517 colspan=6  style='width:388.0pt;border:none;
                                  padding:2.15pt 5.75pt 2.15pt 5.75pt;height:.1in'>
                                  
                                  </td>
                                  <td width=74 style='width:55.5pt;border:none;padding:2.15pt .15in 2.15pt .15in;
                                  height:.1in'>
                                  `+Translation('التوقيع')+`
                                  </td>
                                 </tr>
                                </table>

                                </div>




                                </body>

                                `+print_attach+`

                                </html>`;

                  }else{
                    show_page = 0;
                    
                  }    

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);

                      HTML_VIEW_PAY = HTML_Table + headers + customer_details + attach + attach_other + footers;
                       //  me.data('requestRunning', false);
                     if(show_page==1){
                        $("#invoice_show").html(HTML_VIEW_PAY);
                        $("#inv_numb").val(itm);

                        $('#show_payments_modal').modal('toggle');
                     }else{
                      noty({
                            width: 200,
                            text: Translation('لا توجد وصولات بيع لهذا النوع'),
                            type: 'error',
                            dismissQueue: true,
                            timeout: 2000,
                            layout: 'topRight',
                      });
                     }
                       
                      
                     
                        // window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }
   
    function add_invoice_payment(cust_id){

      $("#add_form")[0].reset();
      $("#customer_id_fk").val('');
      $("#customer_id_fk").val(cust_id);

      $("#saleman_id").val('');
      $("#saleman_id").selectpicker('refresh');
      load_customer_account_details(cust_id);
      


      $('#add_payments_modal').modal('toggle');

    }

    $('#print_pay').click(function(e) {
      e.preventDefault();
         print_invoice('Print','pay');
    });

    $('#pdf_pay').click(function(e) {
      e.preventDefault();
         print_invoice('PDF','pay');
    });


    

    function print_invoice(typ,payment=null){
      if(typ=='Print'){
        window.open().document.write(HTML_VIEW_PAY+print_page);
      }else if(typ=='PDF'){
        var nn = $("#inv_numb").val();
        pdf_generator(HTML_VIEW_PAY,nn,'pay')
      }else{
        window.open().document.write(HTML_VIEW_PAY);
      }
    }

    function pdf_generator(HTML,INV_NO,payment){

                $.ajax({
                      url : 'models/crul_invoice.php',

                      type : 'POST',
                      data : {type:'PDF',html:HTML,inv_no:INV_NO,pay:payment},
                      dataType : 'json',
                      success : function(response) {
                            console.log(response)
                            if(response.is_success == true) {

                                    noty({
                                        width: 200,
                                        text: Translation('تم توليد ملف الـ PDF بنجاح'),
                                        type: 'success',
                                        dismissQueue: true,
                                        timeout: 3000,
                                        layout: 'top',
                                    });
                                    var LINKS = '<a class="btn btn-labeled btn-labeled-left heading-btn btn-info" href="'+response.data+'" target="_blank" style="float: right;">'+Translation('تحميل')+'  <b><i class="icon-file-download"></i></b> </a>';
                                    if(payment !=null){
                                      $("#link_pdf_pay").append(LINKS);
                                    }else{
                                      $("#link_pdf").append(LINKS);
                                    }

                                  
                                  $("#pdf").attr('disabled',false);
                                  $("#pdf_pay").attr('disabled',false);
                                  $("#print").attr('disabled',false);
                                  $("#print_pay").attr('disabled',false);
                            } else {

                               noty({
                                     width: 200,
                                     text: Translation(response.message),
                                     type: 'error',
                                     dismissQueue: true,
                                     timeout: 3000,
                                     layout: 'top',
                               });

                                  $("#pdf").attr('disabled',false);
                                  $("#pdf_pay").attr('disabled',false);
                                  $("#print").attr('disabled',false);
                                  $("#print_pay").attr('disabled',false);
                            }
                      },
                      complete: function() {
                            //   me.data('requestRunning', false);
                      }

                }); // submit ajax
    }

    


    function get_Customer(){

            $.ajax({
                  url : 'models/crul_customer.php',
                  type : 'POST',
                  data : {type:'get'},
                  dataType : 'json',
                  success : function(response) {
                    //console.log(response)
                      var attach ='<option value="" selected="selected">'+Translation('اختيار الزبون')+'</option>';
                      var aaa='';
                        for(var i=response.length-1 ; i >= 0;i--){
                          var tp  = response[i][2];
                          var tp1 = response[i][3];
                          attach = attach + '<option data-subtext="Phone: '+tp+' || E-Mail: '+tp1+'" value="'+response[i][0]+'">'+response[i][1]+'</option>';
                          aaa = aaa + '<option  value="'+response[i][0]+'">'+response[i][1]+'</option>';

                        }
                        $("#customer_id_fk").html(attach);
                        $("#edit_customer_id_fk").html(attach);
                        $('#customer_id_fk').selectpicker('refresh');
                        $("#edit_customer_id_fk").selectpicker('refresh');
                  },
                  complete: function() {
                         //  me.data('requestRunning', false);
                  }

            }); // submit ajax

    }

    function get_City(){

            $.ajax({
                  url : 'models/crul_customer.php',
                  type : 'POST',
                  data : {type:'get_city'},
                  dataType : 'json',
                  success : function(response) {
                    //console.log(response)
                      var attach ='<li><a  href="index.php?p=account_statement"><i class="icon-stackoverflow text-orange-800 text-black"></i><span id="city_filter_link_0">'+Translation('No Filter')+'</span></a></li>';

                    
                        for(var i=response.length-1 ; i >= 0;i--){
                         
                          attach = attach + '<li><a  href="index.php?p=account_statement&cid='+response[i][0]+'"><i class="icon-office text-info"></i> <span id="city_filter_link_'+response[i][0]+'">'+response[i][1]+'</span></a></li>';

                         
                        }
                        $("#city_id_fk").html(attach);
                       
                        
                  },
                  complete: function() {
                         //  me.data('requestRunning', false);
                         change_filter_btn_text();
                  }

            }); // submit ajax

    }


    function change_filter_btn_text(){

      var cid = getQueryVariable("cid");

      if(cid != 'not' && cid != 'all'){
        var text_btn = $("#city_filter_link_"+cid).text();
        $("#stock_btn").text(text_btn);
      }else{
        var text_btn = $("#city_filter_link_0").text();
        $("#stock_btn").text(text_btn);

      }


      
    }

    function get_Item_Type(){

            $.ajax({
                  url : 'models/crul_items.php',
                  type : 'POST',
                  data : {type:'get'},
                  dataType : 'json',
                  success : function(response) {
                    //console.log(response)
                      var attach ='<option value="" selected="selected">'+Translation('جميع الاصناف')+'</option>';
                      attach = attach + '<option value="w" >'+Translation('القروض')+'</option>';
                      var aaa='';
                        for(var i=response.length-1 ; i >= 0;i--){
                          var tp  = response[i][2];
                          var tp1 = response[i][3];
                          attach = attach + '<option  value="'+response[i][0]+'">'+response[i][1]+'</option>';
                          
                        }
                        $("#item_type_id_fk").html(attach);
                        // $('#item_type_id_fk').selectpicker('refresh');
                        
                  },
                  complete: function() {
                         //  me.data('requestRunning', false);
                  }

            }); // submit ajax

    }

   
    function check_paid_amount(){
      var real_paid = parseFloat($("#customer_all_invoices_remaind").attr('data-price-no-format')) ;

      var curnt_pay = parseFloat($("#paid_amount").val());

      // if(curnt_pay > real_paid){
      //   $("#paid_amount").val('');
      //   noty({
      //           width: 200,
      //           text: Translation('المبلغ المدفوع اكبر من المبلغ الكي المتبقي .. الرجاء التحقق من المبلغ'),
      //           type: 'information',
      //           dismissQueue: true,
      //           timeout: 3000,
      //           layout: 'top',
      //       });
      // }
    }


    function compute_remain_price(val,idd){

      
        if(val !="" &&  !isNaN(val) && val !=null && val !=undefined ){
          val = val;
        }else{
          val = 0;
        }
        var old_remain   = $("#total_customer_remaind").attr('data-original-amount');
        if(old_remain   == null || old_remain   == undefined || old_remain   == '' || isNaN(old_remain)){old_remain=0; }
       
        var new_remaind = old_remain - val;
        


    }

    function load_customer_account_details (cust_id){

              $.ajax({
                      url : 'models/crul_invoice.php',
                      type : 'POST',
                      data : {type:'show_payments_for_add',id:cust_id},
                      dataType : 'json',
                      success : function(response) {
                          
                          if(response != 0){
                            
                            
                             

                            $('span[id$="total_customer_account"]').html(currency_format_display(response.invoice[0].total_invoices_price));
                            $('span[id$="total_customer_account"]').attr('data-original-amount',(response.invoice[0].total_invoices_price));
                            
                            $('span[id$="total_customer_discount"]').html(currency_format_display(response.invoice[0].total_payment_discount));
                            $('span[id$="total_customer_discount"]').attr('data-original-amount',(response.invoice[0].total_payment_discount));
                            
                            $('span[id$="total_customer_paid"]').html(currency_format_display(response.invoice[0].total_paid));
                            $('span[id$="total_customer_paid"]').attr('data-original-amount',(response.invoice[0].total_paid));
                         
                            $('span[id$="total_customer_remaind"]').html(currency_format_display(response.invoice[0].total_remained));
                            $('span[id$="total_customer_remaind"]').attr('data-original-amount',(response.invoice[0].total_remained));
                         

                          }else{
                            swal({
                                        title: Translation("خطأ"),
                                        text: Translation(res.data),
                                        confirmButtonColor: "#2196F3",
                                        type: "error"
                                    });
                          }

                            
                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

                }); // submit ajax
    }

    function get_Branch(){

                $.ajax({
                      url : 'models/crul_branch.php',
                      type : 'POST',
                      data : {type:'get',branch_id:BRANCH_ID},
                      dataType : 'json',
                      success : function(response) {
                          var attach ='<option class="text-black text-danger-800" selected="selected" value="">'+Translation('اختيار الفرع')+'</option>';
                          
                          for(var i=response.length-1 ; i >= 0;i--){

                            var tp =response[i][2];
                              
                            attach = attach + '<option class="text-black text-danger-800" data-subtext="'+Translation('الموقع')+' : '+response[i]['location']+'" value="'+response[i]['branch_id']+'">'+response[i]['branch_name']+'</option>';
                              
                               
                              
                          }
                          $("#branch_id_fk").html(attach);
                          $("#branch_id_fk1").html(attach);
                          // $('#branch_id_fk').selectpicker('refresh');

                          $("#edit_branch_id_fk").html(attach);
                          // $('#edit_branch_id_fk').selectpicker('refresh');
                            
                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

                }); // submit ajax

    }

    function get_Saleman(){

            $.ajax({
                  url : 'models/crul_saleman.php',
                  type : 'POST',
                  data : {type:'get'},
                  dataType : 'json',
                  success : function(response) {
                    //console.log(response)
                      var attach ='<option value="" selected="selected">'+Translation('تحديد المندوب')+'</option>';
                      var aaa='';
                        for(var i=response.length-1 ; i >= 0;i--){
                          
                          attach = attach + '<option  data-subtext="'+Translation('هاتف')+': '+response[i][2]+'  " value="'+response[i][0]+'">'+response[i][1]+'</option>';
                          
                        }
                        $("#saleman_id").html(attach);
                        $('#saleman_id').selectpicker('refresh');
                  },
                  complete: function() {
                         //  me.data('requestRunning', false);
                  }

            }); // submit ajax

    }

$(document).ready(function() {
  
    
    get_Customer();
    get_Branch();
    get_Saleman();
    
    
    $('#add_form').submit(function(event) {
      event.preventDefault();
      
    
      var cust_id           = $("#customer_id_fk").val();
      var sale_man          = $("#saleman_id").val();

      var pay_notes_array                  =[];
      var pay_price_array                  =[];


      pay_price_array[0]   = $("#payment_withdraw_amount").val();
      var paid_date         = $("#paid_date").val();
      pay_notes_array[0]   = $("#payment_note").val();

      var paper_number     = $("#paper_number").val();
      var branch_id_fk     = $("#branch_id_fk").val();


      if(pay_price_array[0] =='' || isNaN(pay_price_array[0]) || pay_price_array[0] <=0) {
         $("#payment_withdraw_amount").closest('.form-group').removeClass('has-success');
         $("#payment_withdraw_amount").closest('.form-group').addClass('has-error');
         Check1 = false;
         noty({
                  width: 200,
                  text: Translation("الرجاء قم بادخال مبلغ الدفعه"),
                  type: 'error',
                  dismissQueue: true,
                  timeout: 3000,
                  layout: 'top',
            });
      }else{
         $("#payment_withdraw_amount").closest('.form-group').removeClass('has-error');
         $("#payment_withdraw_amount").closest('.form-group').addClass('has-success');
      }

      if(cust_id =='' || isNaN(cust_id) || cust_id ==0 ) {
         $("#customer_id_fk").closest('.form-group').removeClass('has-success');
         $("#customer_id_fk").closest('.form-group').addClass('has-error');
         Check2 = false;
         noty({
                  width: 200,
                  text: Translation("حصل خطأ الرجاء اعادة تحميل الصفحة والمحاولة من جديد"),
                  type: 'error',
                  dismissQueue: true,
                  timeout: 3000,
                  layout: 'top',
            });
      }else{
         $("#customer_id_fk").closest('.form-group').removeClass('has-error');
         $("#customer_id_fk").closest('.form-group').addClass('has-success');
      }
            

           

      
      


      var Check1 = true;
      var Check2 = true;
      var Check3 = true;
      var Check4 = true;
      var Check5 = true;
      var Check6 = true;

      Check1 = Checks('customer_id_fk');
      Check2 = Checks('payment_withdraw_amount');
      Check3 = Checks('paid_date');
      
      

      if(Check1 && Check2 && Check3 && Check4 && Check5 && Check6){
            $("#submit_add_btn").attr('disabled',true);
            $.ajax({
                url: "models/crul_invoice.php",
                type:"POST",
                dataType: "JSON",
                data : {cust_id             :cust_id,
                        row_payments        :pay_price_array,
                        saleman_id          :sale_man,
                        notes               :pay_notes_array,
                        paid_date           :paid_date,
                        paper_number        :paper_number,
                        branch_id_fk        :branch_id_fk,

                        type                :'add_general_payments'}
            })
            .done(function(res) {
                //alert(res);
                if(res.is_success == true){

                    $("#add_form")[0].reset();
                    $("#customer_id_fk").val('');
                    
                    // get_Customer();

                    $("#total_customer_account").html(currency_format_display(0));
                    $("#total_customer_account").attr('data-original-amount',(0));
                            
                    $("#total_customer_discount").html(currency_format_display(0));
                    $("#total_customer_discount").attr('data-original-amount',(0));
                            
                    $("#total_customer_paid").html(currency_format_display(0));
                    $("#total_customer_paid").attr('data-original-amount',(0));
                         
                    $("#total_customer_remaind").html(currency_format_display(0));
                    $("#total_customer_remaind").attr('data-original-amount',(0));
                         
                    $('#add_payments_modal').modal('toggle');

                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                    
                    noty({
                                    width: 200,
                                    text: Translation(res.data),
                                    type: 'success',
                                    dismissQueue: true,
                                    timeout: 3000,
                                    layout: 'topRight',
                              });

                    
               
                }else{
                    swal({
                        title:"Error",
                        text: Translation(res.data),
                        confirmButtonColor: "#66BB6A",
                        type: "warning"
                    });
                }
                $("#submit_add_btn").attr('disabled',false);
            })
            .fail(function(err) {
                 swal({
                    title: Translation("خطأ"),
                    text: (err),
                    confirmButtonColor: "#66BB6A",
                    type: "error"
                });
                $("#submit_add_btn").attr('disabled',false);
            })
            .always(function() {
                console.log("complete");
            });
        }
    });
    

    

});







$(function() {
//var singleSelect = $('.datatable-column-search-inputs').DataTable();
    
  $(".touchspin-basic").TouchSpin({
        min: 1,
        max: 10000000,
        step: 1,
        buttondown_class: "btn btn-xs",
        buttonup_class: "btn btn-xs"
    });

  $('.daterange-single').daterangepicker({ 
        singleDatePicker: true,
        locale: {
            format: 'YYYY-MM-DD'
        }
    });

  // Mini
    $('.select-size-xs').select2({
        containerCssClass: 'select-xs'
    });


   // Setting datatable defaults
    $.extend( $.fn.dataTable.defaults, {
        autoWidth: false,
        columnDefs: [{ 
            orderable: false,
            width: '100px',
            targets: [ 5 ]
        }],
        dom: '<"datatable-header"fBl><"datatable-scroll"t><"datatable-footer"ip>',
        language: {
            search: '<span>'+Translation('بحث')+':</span> _INPUT_',
            searchPlaceholder: Translation('ابحث عن ')+'...',
            lengthMenu: '<span>'+Translation('عرض')+':</span> _MENU_',
            paginate: { 'first': 'First', 'last': 'Last', 'next': '&larr;', 'previous': '&rarr;' }
        },
        drawCallback: function () {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');
        },
        preDrawCallback: function() {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').removeClass('dropup');
        }
    });


    

    // Individual column searching with text inputs
    $('.datatable-column-search-inputs tfoot td').not(':last-child').each(function () {
        var title = $('.datatable-column-search-inputs thead th').eq($(this).index()).text();
        $(this).html('<input type="text" class="form-control input-sm" placeholder="'+Translation('بحث')+' '+title+'" />');
    });
    
    

   var query_cid   = getQueryVariable("cid");
   var query_typ  = getQueryVariable("typ");




   var table = $('.datatable-column-search-inputs').DataTable({
        
        buttons: {            
            buttons: [
                {
                    extend: 'copyHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: [ 0, ':visible' ]
                    }
                },
                {
                    extend: 'excelHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'pdfHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'print',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'colvis',
                    text: '<i class="icon-three-bars"></i> <span class="caret"></span>',
                    className: 'btn bg-blue btn-icon'
                }
                
            ]
        },
        lengthMenu: [
            [  10, 25, 50, 100 ],
            [  '10', '25', '50', '100' ]
        ],
        "processing": true,
        "serverSide": true,
        "ajax": {
        "url" : "models/crul_account_statement.php",
        "data": function(d){
          d.type = "load";
          if(query_cid !='not'){
            d.cid =query_cid ;
          }
          if(query_typ !='not'){
            d.typ =query_typ ;
          }
          
        }
        },
        drawCallback: function() {
                  $('[data-popup=tooltip]').tooltip();
                  $('[data-popup=popover-custom]').popover({
                    template: '<div class="popover  border-teal-400"><div class="arrow"></div><h3 class="popover-title bg-teal-400"></h3><div class="popover-content"></div></div>'
                  });

            },
        "columnDefs": [
          {
              "targets": 9,
              "data": null,
              "render": function (data,type,row) {

                          var btn = '';

                          if(IS_VIEW ==0){
                                    
                                   btn = `<li class='text-primary-600'>
                                                <a  class='text-purple-400' onclick="add_invoice_payment(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('اضافة دفعه على الحساب')+`'>
                                                    <i class='icon-cash4 icon-2x'></i>`+Translation('اضافة دفعه على الحساب')+`
                                                </a>
                                            </li>`; 
                          }

                          return  `<ul class='icons-list '>
                                         
                                        <li class="dropdown">
                                          <a  class="dropdown-toggle" data-toggle="dropdown"  data-original-title='`+Translation('تفاصيل دفوعات الوصل')+` '>
                                            <i class="icon-menu9"></i>
                                          </a>

                                          <ul class="dropdown-menu dropdown-menu-right">      
                                            
                                            <li class='text-primary-600'>
                                                <a  class='text-info-400' onclick="show_summary(`+row[0]+`,'`+row[1]+`','`+row[2]+`','`+row[9]+`','`+row[10]+`')" data-popup='tooltip' data-original-title='`+Translation('عرض خلاصة حسابات الزبون')+`'>
                                                    <i class='icon-file-spreadsheet2 icon-2x'></i>`+Translation('عرض خلاصة حسابات الزبون')+`
                                                </a>
                                            </li>

                                            <li class='text-primary-600'>
                                                <a  class='text-warning-400' onclick="load_all_invoices_just_totals(`+row[0]+`,'`+row[1]+`','`+row[2]+`','`+row[9]+`','`+row[10]+`')" data-popup='tooltip' data-original-title='`+Translation('عرض حساب الزبون بدون تفاصيل')+`'>
                                                    <i class='icon-eye8 icon-2x'></i>`+Translation('عرض حساب الزبون بدون تفاصيل')+`
                                                </a>
                                            </li>


                                            <li class='text-primary-600'>
                                                <a  class='text-success-400' onclick="load_all_invoices_full_detail(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('عرض حساب الزبون مع كافة التفاصيل')+`'>
                                                    <i class='icon-eye8 icon-2x'></i>`+Translation('عرض حساب الزبون مع كافة التفاصيل')+`
                                                </a>
                                            </li>

                                            
                                            `+btn+`
                                            

                                            
                                            

                                          </ul>
                                        </li>
                                        
                                    </ul>`;


                        }
          },


            {
               "render": function(data, type, row){


                        // return  `<a onclick="show_invoice(`+row[0]+`)"  data-popup='tooltip' data-original-title='Show Invoice Details'>`+data+`</a>`;
                        return  `<a onclick="load_all_invoices(`+row[0]+`,'`+row[1]+`','`+row[2]+`','`+row[9]+`','`+row[10]+`')"  data-popup='tooltip' data-original-title='`+Translation('عرض جميع كشوفات الحساب لهذا الزبون')+`'>`+data+`</a>`;


               },
               "targets": 1
            },

            {
                "render": function(data, type, row){


                                                                      
                                            

                     status=  ``;
                     status= status +  ` 
                                          <span class=" label-rounded bg-blue ">`+row[7]+`</span>
                                         `;
                     // status= status +  `
                     //                      <span class="label  bg-pink-400 btn-block">`+Translation('عدد وصولات القروض')+` <span class=" label-rounded bg-blue pull-right">`+row[8]+`</span></span>
                     //                    `;
                     

                  
                   return  status;
                },
                "targets": 7
            },
            
            {
                "render": function(data, type, row){

                    return currency_format_display(data);
                },
                "targets": 3
            },

            {
                "render": function(data, type, row){

                    return currency_format_display(data);
                },
                "targets": 4
            },

            {
                "render": function(data, type, row){

                    return currency_format_display(data);
                },
                "targets": 5
            },

            {
                "render": function(data, type, row){

                    return currency_format_display((row[3] - row[5] - row[4]) );
                },
                "targets": 6
            },

            
            

            {
                "render": function(data, type, row){
                  var remin = (row[3] - row[5] - row[4]);
                   if(remin == 0 ){
                     status=  '<span class="label label-success btn-block ">'+Translation('واصل')+'</span>';
                   }else if(remin >0 && row[5] >0){
                     status = '<span class="label bg-orange-400  btn-block ">'+Translation('واصل جزئيا')+'  </span>';
                   }else if(remin >0 && row[5] == 0){
                     status = '<span class="label bg-danger-400  btn-block ">'+Translation('غير واصل')+'  </span>';
                   }else if(remin <0){
                     status = '<span class="label bg-violet  btn-block ">'+Translation('المبلغ المدفوع اكبر من الكلي')+'  </span>';
                   }else{
                     status = '<span class="label bg-violet  btn-block ">'+Translation('غير معروف')+'  </span>';
                   }
                   return  status;
                },
                "targets": 8
            }
            

           
        ],
        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {

            var remin = (aData[3] - aData[5] - aData[4]);

            if(   remin > 0 ){ // outcome type
                $(nRow).children().each(function (index, td) {
                    $(this).addClass('alpha-danger');
                });
            }else if(remin == 0){
                $(nRow).children().each(function (index, td) {
                    $(this).addClass('alpha-success');
                });
            }
        },
        "order": [[0,'desc']],
        "displayLength": 25,
      
        initComplete: function () {


          $("div.datatable-header").append(`&nbsp;<div class="btn-group">
                                          <button type="button" 
                                          class="btn bg-teal-400 btn-labeled dropdown-toggle" 
                                          data-toggle="dropdown"><b><i class="icon-filter4">
                                          </i></b><span id="stock_btn">`+Translation('City')+`</span>  <span class="caret"></span></button>
                                          <ul class="dropdown-menu dropdown-menu-right" id="city_id_fk">
                                          </ul>
                                          </div>`); 
         
         // $("div.datatable-header").append(`<a data-toggle="collapse"
         //                              style="margin-right:10px;"
         //                              data-target="#add-form-cont"
         //                              href="javascript:;"
         //                              aria-controls="add-form-cont"
         //                              aria-expanded="false"
         //                              class="btn btn-primary"
         //                              id="add_Item_Btn">
         //                                <i class="`+CURRENT_BTN_ICON+`"></i> `+CURRENT_BTN+`
         //                            </a>`); 

          // $("div.datatable-header").append(`&nbsp;<div class="btn-group">
          //                 <button id="inv_filter_btn" type="button"
          //                 class="btn bg-teal-400 btn-labeled dropdown-toggle"
          //                 data-toggle="dropdown"><b><i class="icon-filter4">
          //                 </i></b> <span id="inv_filter">فلترة الوصولات</span> <span class="caret"></span></button>
          //                 <ul class="dropdown-menu dropdown-menu-right">
          //                 <li><a href="index.php?p=invoice_curt&typ=`+query_typ+`"><i class="icon-close2 text-teal"></i> ازالة الفلتر </a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=2"><i class="icon-coins text-success"></i> الواصل</a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=1"><i class="icon-bell-check text-info"></i> واصل جزئيا </a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=0"><i class="icon-alarm-check text-danger"></i> غير واصل</a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=4"><i class=" icon-task text-violet"></i> عرض </a></li>
          //                 <li><a href="index.php?p=invoice&ip=3"><i class="icon-loop text-purple"></i> مسترجع </a></li>

          //               </ul>
          //             </div>`);
 
            // invoce_filter_btn_label();

            this.api().columns().every( function() {
                var column = this;
                

            });
            // escape_notes();

            get_City();

        }
    });

    
    table.columns().every( function () {
        var that = this;
        $('input', this.footer()).on('keyup change', function () {
            that.search(this.value).draw();
        });
    });


    // Single row selection
    
    $('.datatable-column-search-inputs tbody').on('click', 'tr', function() {
        if ($(this).hasClass('success')) {
            $(this).removeClass('success');
        }
        else {
            table.$('tr.success').removeClass('success');
            $(this).addClass('success');
        }
    });


         // change filter to top
    $('.datatable-column-search-inputs tfoot tr').insertAfter($('.datatable-column-search-inputs thead tr'))


    $('.dataTables_length select').select2({
        minimumResultsForSearch: Infinity,
        width: 'auto'
    });


});



