cfrom=new Contact($this->mfrom_san); $this->cto=new Contact($this->mto_san); $this->gs_num=$this->isa_num; $splitnotes=split("\n",$this->note); $recombined_notes=''; foreach($splitnotes as $k) { $wline=$k; while(strlen($wline) > 60) { $recombined_notes .= "NTE*INT*".substr($wline,0,60)."\n"; $wline=substr($wline,60); } $recombined_notes .= "NTE*INT*".substr($wline,0,60)."\n"; } $curdate=date("Ymd"); $curtime=date("Hi"); $this->raw_output=''; // isa header first. 4th char * is the seperator character. $this->raw_output .= sprintf("ISA*00*TBMWEBSTOR*00* *ZZ*%-15.15s*ZZ*%-15.15s*%s*%s*U*00200*%09d*0*P*>\n",$this->mto_san,$this->mfrom_san,date("ymd"),$curtime,$this->isa_num); // group segment $this->raw_output .= sprintf("GS*PO*%s*%s*%s*%s*%d*X*004010\n",$this->mto_san,$this->mfrom_san,$curdate,$curtime,$this->gs_num); $this->raw_output .= sprintf("ST*850*0001\n"); $stseg=''; $stseg .= sprintf("BEG*00*NE*%s**%s*OL%s*AC\n",((strlen($this->ponum)>0)?($this->ponum):("OL".$this->isa_num)),$curdate,$this->isa_num); ## use po# if set, else $this->isa_num $stseg .= $recombined_notes; ## NTE segments $stseg .= "CSH*O\n"; // means back order if OS or NYP $stseg .= "DTM*001*20050611\n"; // xxx date + a month? 2? $stseg .= sprintf("N1*VN*%s*15*%s\n",strip_accents($this->cfrom->getName()),$this->mfrom_san); // 15 means next item will be a san, vend0r $stseg .= sprintf("N3*%s*%s\n",strip_accents($this->cfrom->getAddr1()),strip_accents($this->cfrom->getAddr2())); // vn addr $stseg .= sprintf("N4*%s*%s*%s*%s**\n",strip_accents($this->cfrom->getCity()),$this->cfrom->getProv(),$this->cfrom->getPostal(),conv_country_to_countrycode($this->cfrom->getCountry())); // vn addr $stseg .= sprintf("N1*BT*%s*15*%s\n",strip_accents($this->cto->getName()),$this->mto_san); // bill to $stseg .= sprintf("N3*%s*%s\n",strip_accents($this->cto->getAddr1()),strip_accents($this->cto->getAddr2())); // bill to addr $stseg .= sprintf("N4*%s*%s*%s*%s**\n",strip_accents($this->cto->getCity()),strip_accents($this->cto->getProv()),$this->cto->getPostal(),conv_country_to_countrycode($this->cto->getCountry())); // vn addr $stseg .= sprintf("N1*ST*%s*15*%s\n",strip_accents($this->cto->getName()),$this->mto_san); // ship to $stseg .= sprintf("N3*%s*%s\n",strip_accents($this->cto->getAddr1()),strip_accents($this->cto->getAddr2())); // ship to addr $stseg .= sprintf("N4*%s*%s*%s*%s**\n",strip_accents($this->cto->getCity()),$this->cto->getProv(),$this->cto->getPostal(),conv_country_to_countrycode($this->cto->getCountry())); // vn addr if($this->shiptype=='ship') { $stseg .= "TD5****T*401 Ship\n"; } elseif($this->shiptype=='pickup') { $stseg .= "TD5****H*405 Pickup\n"; } else { $stseg .= "TD5****H*405 Pickup\n"; } $contactname=strip_accents($this->cto->getContacts()); if(strlen($contactname)==0) { $contactname=strip_accents($this->cto->getName()); } $stseg .= sprintf("PER*OD*%s*TE*%s\n",$contactname,$this->cto->getPhone()); $stseg .= sprintf("PER*OD*%s*FX*%s\n",$contactname,$this->cto->getFax()); $stseg .= sprintf("PER*OD*%s*EM*%s\n",$contactname,$this->cto->getEmail()); // get list of all isbns $items=array(); foreach($this->data as $row) { $carttitle=$row['carttitle']; $linepo=$carttitle->getLinepo(); $items[$carttitle->getIsbn()][$linepo]['carttitle']=$carttitle; $items[$carttitle->getIsbn()][$linepo]['title']=$row['title']; $items[$carttitle->getIsbn()][$linepo]['supps'][]=$carttitle; $items[$carttitle->getIsbn()][$linepo]['qty']+=$carttitle->getQty(); } // foreach isbn... $total_items=0; foreach($items as $_bn=>$linepos) { foreach($linepos as $_linepo=>$row) { $ct=$row['carttitle']; $to=$row['title']; $pq=$to->getPriceQuote(); $keytypes=array(); $keytypes[]=$this->PO_getKeyCodeString($to->getIsbn()); if($upc=$to->getUpc()) { $t=$this->PO_getKeyCodeString($upc); if($t != $keytypes[0]) $keytypes[]=$t; } $stseg .= sprintf("PO1*%s*%d*UN*%s*SR*%s\n",$ct->getLinepo(),$row['qty'],$ct->getCa_cust_retail(),join('*',$keytypes)); $stseg .= sprintf("CTP**SLP*%s***DIS*%.2f\n",$ct->getCa_cust_retail(),sprintf("%.2f",(100-$ct->getCa_cust_disc())/100)); $stseg .= sprintf("PID*F****%s\n",$to->getTitle()); foreach($row['supps'] as $v) { $stseg .= sprintf("PWK*******%s,%s,%d,%.2f,%.2f,%s*\n",$v->getSupplier_loc(),$v->getOrder_group(),$v->getQty(),$v->getOprice(),$v->getPubprice(),$v->getDiscount()); } $total_items+=$row['qty']; } } $stseg .= sprintf("CTT*%d*%d\n",count($items),$total_items); // totals. count($items) is count of unique isbns $stseg_ar=split("\n",$stseg); $this->raw_output .= $stseg; $this->raw_output .= sprintf("SE*%s*0001\n",count($stseg_ar)); $this->raw_output .= sprintf("GE*1*%d\n",$this->gs_num); $this->raw_output .= sprintf("IEA*1*%09d\n",$this->isa_num); ?>