'DESPAT_4 - BOSS only - prints copy of invoice with coloured header for emailing as PDF external vloadif() dpath sch scw messboxwait() navrecs() fgp bgp cpath external increment() PrintReport() messbox() progress() delidxrec() bgi external chkdate() fentrybox() entryline() bgs fgi fgs chkfname() gdsoutpath external makeidx() remove() vunloadif() vatrate Background() invpath external getidxrecs() shopmask userid addidxrec() progtag() colpopup() external chkstr() strcount() bpopdb() colpoplines() X_path Xreppath external _SWIP_Crystal() scbtm() _GEMS_ShellEx() public ptval ptstr dsa jobnr invdate psa $nextinvnr #vat #net #gross $invdate public #receipts #due custdet[1,1] ftrarray[1] $dateftr $ftrcode #SWIP_Error global x $index $file InvDetails() EnterOrder() S_status global ProcessInvoice() y2 y3 c $cn global #uninv PrintInvoice() global mth ld from_date last_m_e cm CheckDirectory() sym l c2 r2 global ReplaceHardSpace() $title custname addr1 addr2 custcity custcode global recs plist[1,1] mr dc lc sc pl i global pc rec drows k pg tr global abbrv_name #invrecnr #prec Key t1 t5 t6 S_details global w_$title t3 w_addr1 t4 w_addr2 y1 z $schref global w_custname w_custcity w_custcode w_abbrv_name $line global SetupDetails() slotrec $ordstat global $invoice $invnr cr_status bot clf clb global $dfa1 $ftrappts global #ftrappts $day_1 $fitter $fname ftrname ReplaceHardSpace2() global $ftgstr #amount varndes PrintCustCopy() ' global SetupDetails2() str1 p5 global ReplaceSoftSpace() ClearHardSpaces() $pdf MAIN single-step off 'message "Using SW2K_NEW"message "Xreppath) is:"&str(Xreppath) Background() bot = 7 clb = 13 clf = 10 ' redimension custdet[11,2] messboxwait(" Prints copy invoice with coloured header for emailing PDF ",0,0,1) Background() EnterOrder() file unload all END MAIN FUNCTION EnterOrder() ' while true file unload all Background() vloadif(dpath|"despat_2.vw") order change key "[Job_Nr]" x = fentrybox(" Enter Order Nr or {Esc} to exit ",6,shopmask,"") if x = -1 return (-1) elseif x = 0 jobnr = ptstr data find "[Job_Nr]" equal jobnr options "" if cerror ' if none - then return messboxwait(" Job Nr"&jobnr&"not found ",0,0,1) return (1) end if x = SetupDetails() if x = -1 return (-1) ' elseif x = 1 ' continue while end if x=ProcessInvoice(1) ' if x = -1 ' repaint off ' return (-1) ' end if end if ' end while END FUNCTION ' EnterOrder() FUNCTION SetupDetails() progress(fgp,bgp," Checking for existing order ",0) vloadif(dpath|"ordstat4.vw") order change key "[Job_Nr]" data find "[Job_Nr]" equal jobnr options "gw" if cerror ' if none - then return messbox(" Job not found ",1,0,0) return (-1) else slotrec = [Appt_Slots] $ordstat = [Order_Status] $invoice = [Completed] $invnr = [Inv_Nr] $invdate = [Invoice_Date] #prec=precord 'message "#prec is:"&str(#prec) repaint on repaint ' ShowStatus() screen save 1 1 8 scw S_details repaint off screen shortrestore S_details vunloadif("ordstat4.vw") return (0) end if END FUNCTION ' SetupDetails() FUNCTION ProcessInvoice(n) local currjobnr ' repaint off $nextinvnr = $invnr vloadif(dpath|"inv_1L.vw") data goto record record-number #prec x = PrintInvoice() if x = 1 return (1) end if ' message "jobnr is:"&str(jobnr) Background() ' messbox(" Has invoice nr"&$nextinvnr&"printed correctly? (y/n) ",1,1,1) ' if ptstr == "y" ' store file & exit ' return (1) ' end if END FUNCTION ' ProcessInvoice() FUNCTION InvDetails() local #sumgross s #due = [Balance_Due] 'message "#due is:"&str(#due) #gross = [Invoice_Total] 'message "#gross is:"&str(#gross) #sumgross = tablesum([Amount_Gross]) 'message "#sumgross is:"&str(#sumgross) ' message "#gross is:"&str(#gross) ' message "#sumgross is:"&str(#sumgross) s=abs(#gross-#sumgross) ' message "s is:"&str(s) ' if abs(#gross-#sumgross)>.1 ' message " Gross Invoice value WRONG - inform Head Office " ' return (1) ' end if #receipts = tablesum([Amount_Received])'message "#receipts is:"&str(#receipts) ' if abs((#gross - #receipts)-#due)>.01 ' x = (#gross - #receipts) - #due 'message "x is:"&str(round(x,20)) ' messboxwait(" Cash receipts WRONG (diff of"¤cy(x)|") - inform Head Office ",0,0,1) ' return (1) ' end if #receipts = "’’Payments received by"&date2(invdate)&"’’"¤cy(tablesum([Amount_Received])) ' #net = #gross/((100+vatrate)/100) ' #net = [Net_Invoice] 'message "#net is:"&str(#net) #vat = #gross - #net 'message "#vat is:"&str(#vat) ' if abs(#gross-#net-#vat)>.01 ' x = (#gross - #net)-#vat 'message "x is:"&str(round(x,20)) ' messboxwait(" VAT WRONG (diff of"¤cy(x)|") - inform Head Office ",0,0,1) ' return (1) ' end if #net = "’’Net invoice value:"¤cy(#net) 'message "#net is:"&str(#net) ' #vat = "- VAT @"&str(vatrate)|"%"¤cy(#vat) 'message "#vat is:"&str(#vat) #vat = "(VAT @"&str(vatrate)|"%"¤cy(#vat)|")" if #due > 0 #due = "’Balance now due"¤cy(#due) elseif #due = 0 #due = "’’’Invoice paid in full" else #due = "" end if #gross = "- TOTAL Invoice value"¤cy(#gross) END FUNCTION ' InvDetails() FUNCTION ReplaceHardSpace(str1) local j r m bw l_last #addn bw = 39 ' boxwidth m = "" for j = 1 to len(str1) r = mid(str1,j,1) if r = " " r = "’" ' replace hard space end if m = m|r end for if len(m) < bw #addn = bw-len(m) else #addn = mod(len(m),bw) end if m = m|repeat("’",#addn) return (m) END FUNCTION ' ReplaceHardSpace() FUNCTION CheckDirectory() local invpath invpath = left(dpath,1)|":\reports\invoices\"|mid(date1(invdate),4,3)|"-"|right(date1(invdate),2)|"\" x = chkfname(invpath|"*.*") if x = 0 'message "Valid" return (0) elseif x = -6 'message "Bad path" messboxwait(invpath&"not found ",0,0,1) return (1) elseif x = -5 'message "Bad character at"&str(ptval) messboxwait(invpath&"not found ",0,0,1) return (1) end if END FUNCTION ' CheckDirectory() FUNCTION ReplaceHardSpace2(str1,bw) local j r m l_last #addn m = "" for j = 1 to len(str1) r = mid(str1,j,1) if r = " " r = "’" ' replace hard space end if m = m|r end for if len(m) < bw #addn = bw-len(m) else #addn = mod(len(m),bw) end if m = m|repeat("’",#addn) return (m) END FUNCTION ' ReplaceHardSpace2() FUNCTION PrintCustCopy() ' returns 0 for Office copy only or 1 for both if left([Job_Nr],1)="W" return (1) elseif [Balance_Due]>.1 return (1) elseif [Delivery_Address_1]<>[Address_1] return (1) else messbox("Invoice total"¤cy([Invoice_Total])&"- print ONLY the Office copy? (y/n) ",1,1,1) if ptstr == "y" return (0) else return (1) end if end if ' routine to decide whether to print customer's copy ' i.e o/s balance; diff invoice & delivery addresses; END FUNCTION ' PrintCustCopy() FUNCTION ReplaceSoftSpace(str1) local j r m l_last #addn m = "" for j = 1 to len(str1) r = mid(str1,j,1) if r = "’" r = " " ' replace with soft space end if m = m|r end for return (m) END FUNCTION ' ReplaceSoftSpace() FUNCTION ClearHardSpaces() 'message "ClearHardSpaces()" vloadif(X_path|"X_inv_a.vws") t1=dbget("[Title]") 'message "t1 is:"&str(t1) t1=ReplaceSoftSpace(t1) 'message "t1 is:"&str(t1) ' lock-record ' x=dbput("[Title]",t1) ' write-record vunloadif("X_inv_a.vws") vloadif(X_path|"X_inv_b.vws") for i = 1 to records t1=dbget("[Reason]") 'message "t1 is:"&str(t1) t1=ReplaceSoftSpace(t1) 'message "t1 is:"&str(t1) ' lock-record ' x=dbput("[Reason]",t1) ' write-record end for order change physical vunloadif("X_inv_b.vws") END FUNCTION ' ClearHardSpaces() FUNCTION PrintInvoice() x = InvDetails() if x = 1 return (1) end if Background() $index = "onlyone.idx" $file = "cust_ord" remove($index) x = makeidx($file,$index,str(precord),3) ' message "x is:"&str(x) order change index $index $cn=0 if [Invoice_Total] < 0 ' Credit Notes $cn=1 ' set marker end if remove(X_path|"X_inv_a.*") data query execute "not_del.dfq" Smart4 X_path|"X_inv_a" fields "[1|"|str(dbinfo(db_fields))|"]" vunloadif("X_inv_a.vws") vloadif(dpath|"variat_n.vws") remove(X_path|"X_inv_b.*") data query execute "allVreqn.dfq" Smart4 X_path|"X_inv_b" fields "[1|"|str(dbinfo(db_fields))|"]" vunloadif("X_inv_b.vws") ' vloadif(X_path|"X_inv_a.vws") ' lock-record ' [Inv_Nr]=$nextinvnr ' write-record vunloadif("X_inv_a.vws") ClearHardSpaces() vloadif(dpath|"inv_1L.vw") $pdf=invpath|$nextinvnr|".pdf" 'message "$pdf is:"&str($pdf) if $cn=0 if PrintCustCopy()=1 ' print BOTH copies _SWIP_Crystal(Xreppath|"invcustl","S",0,1,"") ' _SWIP_Crystal(Xreppath|"invcustl","EP",0,1,$pdf) end if else ' Credit Note _SWIP_Crystal(Xreppath|"crn_cust","S",0,1,"") end if if file($pdf) = TRUE _GEMS_ShellEx("open",$pdf,"",8) end if vloadif(dpath|"despat_3.vw") order change key "[Job_Nr]" data find "[Job_Nr]" equal jobnr options "" END FUNCTION ' PrintInvoice()