Friday, March 10, 2017

how to save a bill on local disk (thermal paper)

I develop POS software on web service but I want to save a bill on Local drive C:/

I use code "printer_open" but it can not save a copy.

I think, I will use the PDF to create a bill. But PDF can be flexible (long or short bill out) contents. and not divide it? Or are there the others way?

code invoice print

$handle = printer_open("EPSON TM-T88IV Receipt");
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_set_option($handle, PRINTER_PAPER_WIDTH, 50.8);
printer_set_option($handle, PRINTER_PAPER_LENGTH, 3276);

printer_start_doc($handle, "My Document");
printer_start_page($handle);

$font = printer_create_font("Tahoma", 30, 8, 400, false, false, false, 0);
printer_select_font($handle, $font);

printer_draw_bmp($handle, "D:\\logo.bmp", 10, 0);

printer_draw_text( $handle, iconv("UTF-8", "TIS-620", $_POST["tPrintHeader"] . " Branch" . $_POST["tBranchName"]), 10, 100);

printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "TaxID  " . $_POST["tTaxID"]), 10, 130);

printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "POS No.  " . $_POST["tMachineNo"]), 10, 160);

printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Invoice No.  " . $_POST["tInvoiceNo"]), 10, 190);

printer_draw_text( $handle, $_POST["tInvoiceTime"], 10, 220);

printer_draw_line( $handle, 10, 260, 360, 260);

$TotalRow = $_POST["tRow"];

$TotalPiece = 0;
$TotalPrice = 0;

for ($x=0; $x<$TotalRow; $x++) {

    $ThisRow = "row" . $x;
    $ThisData = $_POST[$ThisRow];

    list($BarCode, $Contain, $ProductName, $Price, $Quantity) = explode("||", $ThisData);

    $P_Name = iconv("UTF-8", "TIS-620", $ProductName);

    printer_draw_text( $handle, "(" . $Contain . ")" . $P_Name, 10, (($x * 60) + 270));

    if ($Price < 10) {
        printer_draw_text( $handle, $Price, 180, (($x * 60) + 300));
    } elseif ($Price < 100) {
        printer_draw_text( $handle, $Price, 170, (($x * 60) + 300));
    } elseif ($Price < 1000) {
        printer_draw_text( $handle, $Price, 160, (($x * 60) + 300));
    } elseif ($Price < 10000) {
        printer_draw_text( $handle, number_format($Price, 2), 145, (($x * 60) + 300));
    }

    if ($Quantity <= -1000) {
        printer_draw_text( $handle, "(" . number_format($Quantity) . ")", 205, (($x * 60) + 300));
    } elseif ($Quantity <= -100) {
        printer_draw_text( $handle, "(" . $Quantity . ")", 220, (($x * 60) + 300));
    } elseif ($Quantity <= -10) {
        printer_draw_text( $handle, "(" . $Quantity . ")", 230, (($x * 60) + 300));
    } elseif ($Quantity < 0) {
        printer_draw_text( $handle, "(" . $Quantity . ")", 240, (($x * 60) + 300)); 
    } elseif ($Quantity < 10) {
        printer_draw_text( $handle, $Quantity, 260, (($x * 60) + 300));
    } elseif ($Quantity < 100) {
        printer_draw_text( $handle, $Quantity, 250, (($x * 60) + 300));
    } elseif ($Quantity < 1000) {
        printer_draw_text( $handle, $Quantity, 240, (($x * 60) + 300));
    } elseif ($Quantity < 10000) {
        printer_draw_text( $handle, number_format($Quantity), 225, (($x * 60) + 300));
    }

    $ItemPrice = $Price * $Quantity;
    if ($ItemPrice <= -10000) {
        printer_draw_text( $handle, "(" . number_format($ItemPrice, 2) . ")", 260, (($x * 60) + 300));
    } elseif ($ItemPrice <= -1000) {
        printer_draw_text( $handle, "(" . number_format($ItemPrice, 2) . ")", 270, (($x * 60) + 300));
    } elseif ($ItemPrice <= -100) {
        printer_draw_text( $handle, "(" . number_format($ItemPrice, 2) . ")", 285, (($x * 60) + 300));
    } elseif ($ItemPrice <= -10) {
        printer_draw_text( $handle, "(" . number_format($ItemPrice, 2) . ")", 295, (($x * 60) + 300));
    } elseif ($ItemPrice < 0) {
        printer_draw_text( $handle, "(" . number_format($ItemPrice, 2) . ")", 305, (($x * 60) + 300));  
    } elseif ($ItemPrice < 10) {
        printer_draw_text( $handle, number_format($ItemPrice, 2), 325, (($x * 60) + 300));
    } elseif ($ItemPrice < 100) {
        printer_draw_text( $handle, number_format($ItemPrice, 2), 315, (($x * 60) + 300));
    } elseif ($ItemPrice < 1000) {
        printer_draw_text( $handle, number_format($ItemPrice, 2), 305, (($x * 60) + 300));
    } elseif ($ItemPrice < 10000) {
        printer_draw_text( $handle, number_format($ItemPrice, 2), 290, (($x * 60) + 300));
    } elseif ($ItemPrice < 100000) {
        printer_draw_text( $handle, number_format($ItemPrice, 2), 280, (($x * 60) + 300));
    } elseif ($ItemPrice < 1000000) {
        printer_draw_text( $handle, number_format($ItemPrice, 2), 270, (($x * 60) + 300));
    }
    $TotalPiece = $TotalPiece + $Quantity;
    $TotalPrice = $TotalPrice + $ItemPrice;
}

    printer_draw_line( $handle, 10, (($x * 60) + 275), 360, (($x * 60) + 275));
    $client_piece = str_replace(",", "", $_POST["tPiece"]);
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Total  "), 10, (($x * 60) + 285));
    if ($client_piece < 10) {
        printer_draw_text( $handle, $client_piece, 90, (($x * 60) + 285));
    } elseif ($client_piece < 100) {
        printer_draw_text( $handle, $client_piece, 80, (($x * 60) + 285));
    } elseif ($client_piece < 1000) {
        printer_draw_text( $handle, $client_piece, 70, (($x * 60) + 285));
    } elseif ($client_piece < 10000) {
        printer_draw_text( $handle, number_format($client_piece, 0), 55, (($x * 60) + 285));
    } elseif ($client_piece < 100000) {
        printer_draw_text( $handle, number_format($client_piece, 0), 45, (($x * 60) + 285));
    } elseif ($client_piece < 100000) {
        printer_draw_text( $handle, number_format($client_piece, 0), 35, (($x * 60) + 285));
    }
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "  pcs"), 100, (($x * 60) + 285));

    $client_amount = str_replace(",", "", $_POST["tAmount"]);
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Value"), 150, (($x * 60) + 285));
    if ($client_amount < 10) {
        printer_draw_text( $handle, number_format($client_amount, 2), 280, (($x * 60) + 285));
    } elseif ($client_amount < 100) {
        printer_draw_text( $handle, number_format($client_amount, 2), 270, (($x * 60) + 285));
    } elseif ($client_amount < 1000) {
        printer_draw_text( $handle, number_format($client_amount, 2), 260, (($x * 60) + 285));
    } elseif ($client_amount < 10000) {
        printer_draw_text( $handle, number_format($client_amount, 2), 245, (($x * 60) + 285));
    } elseif ($client_amount < 100000) {
        printer_draw_text( $handle, number_format($client_amount, 2), 235, (($x * 60) + 285));
    } elseif ($client_amount < 1000000) {
        printer_draw_text( $handle, number_format($client_amount, 2), 225, (($x * 60) + 285));
    }
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "USD"), 325, (($x * 60) + 285));

    $client_discount = str_replace(",", "", $_POST["tDiscount"]);
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Discount"),  151, (($x * 60) + 315));
    if ($client_discount < 10) {
        printer_draw_text( $handle, number_format($client_discount, 2), 280, (($x * 60) + 315));
    } elseif ($client_discount < 100) {
        printer_draw_text( $handle, number_format($client_discount, 2), 270, (($x * 60) + 315));
    } elseif ($client_discount < 1000) {
        printer_draw_text( $handle, number_format($client_discount, 2), 260, (($x * 60) + 315));
    } elseif ($client_discount < 10000) {
        printer_draw_text( $handle, number_format($client_discount, 2), 245, (($x * 60) + 315));
    } elseif ($client_discount < 100000) {
        printer_draw_text( $handle, number_format($client_discount, 2), 235, (($x * 60) + 315));
    } elseif ($client_discount < 1000000) {
        printer_draw_text( $handle, number_format($client_discount, 2), 225, (($x * 60) + 315));
    }
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "USD"), 325, (($x * 60) + 315));

    printer_draw_text( $handle, $_POST["tThaiName"], 10, (($x * 60) + 345));

    $client_cash = str_replace(",", "", $_POST["tCash"]);
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Cash"),  137, (($x * 60) + 345));
    if ($client_cash < 10) {
        printer_draw_text( $handle, number_format($client_cash, 2), 280, (($x * 60) + 345));
    } elseif ($client_cash < 100) {
        printer_draw_text( $handle, number_format($client_cash, 2), 270, (($x * 60) + 345));
    } elseif ($client_cash < 1000) {
        printer_draw_text( $handle, number_format($client_cash, 2), 260, (($x * 60) + 345));
    } elseif ($client_cash < 10000) {
        printer_draw_text( $handle, number_format($client_cash, 2), 245, (($x * 60) + 345));
    } elseif ($client_cash < 100000) {
        printer_draw_text( $handle, number_format($client_cash, 2), 235, (($x * 60) + 345));
    } elseif ($client_cash < 1000000) {
        printer_draw_text( $handle, number_format($client_cash, 2), 225, (($x * 60) + 345));
    }
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "USD"), 325, (($x * 60) + 345));


    $IsCard = "N";
    $CardAdd = 0;
    $client_card = str_replace(",", "", $_POST["tCard"]);
    if ($client_card > 0) {
        $IsCard = "Y";
        $CardAdd = 30;
        printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Credit Card"),   137, (($x * 60) + 375));
        if ($client_card < 10) {
            printer_draw_text( $handle, number_format($client_card, 2), 280, (($x * 60) + 375));
        } elseif ($client_card < 100) {
            printer_draw_text( $handle, number_format($client_card, 2), 270, (($x * 60) + 375));
        } elseif ($client_card < 1000) {
            printer_draw_text( $handle, number_format($client_card, 2), 260, (($x * 60) + 375));
        } elseif ($client_card < 10000) {
            printer_draw_text( $handle, number_format($client_card, 2), 245, (($x * 60) + 375));
        } elseif ($client_card < 100000) {
            printer_draw_text( $handle, number_format($client_card, 2), 235, (($x * 60) + 375));
        } elseif ($client_card < 1000000) {
            printer_draw_text( $handle, number_format($client_card, 2), 225, (($x * 60) + 375));
        }
        printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "USD"), 325, (($x * 60) + 375));
    }

    $client_back = str_replace(",", "", $_POST["tBack"]);
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "Change"),    143, (($x * 60) + 375 + $CardAdd));
    if ($client_back < 10) {
        printer_draw_text( $handle, number_format($client_back, 2), 280, (($x * 60) + 375 + $CardAdd));
    } elseif ($client_back < 100) {
        printer_draw_text( $handle, number_format($client_back, 2), 270, (($x * 60) + 375 + $CardAdd));
    } elseif ($client_back < 1000) {
        printer_draw_text( $handle, number_format($client_back, 2), 260, (($x * 60) + 375 + $CardAdd));
    } elseif ($client_back < 10000) {
        printer_draw_text( $handle, number_format($client_back, 2), 245, (($x * 60) + 375 + $CardAdd));
    } elseif ($client_back < 100000) {
        printer_draw_text( $handle, number_format($client_back, 2), 235, (($x * 60) + 375 + $CardAdd));
    } elseif ($client_back < 1000000) {
        printer_draw_text( $handle, number_format($client_back, 2), 225, (($x * 60) + 375 + $CardAdd));
    }
    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "USD"), 325, (($x * 60) + 375 + $CardAdd));


    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "vat include"),   10, (($x * 60) + 405 + $CardAdd));


    printer_draw_text( $handle, iconv("UTF-8", "TIS-620", "c = current tax"),   10, (($x * 60) + 435 + $CardAdd));

    printer_delete_font($font);

    printer_end_page($handle);

    printer_end_doc($handle);

    printer_close($handle);

invoice print out. It work. But it can not save a copy.



via w.thanapon

Advertisement