1 year ago

Need help in saving Invoice data

Posted 1 year ago by Zaheer

I have a standard invoice with header info and multiple products in an html table. Can save header information but cannot figure out how to save the products. I am using a Modal form with Ajax to send data to Controller. My Ajax code is as under :

            $('#saveBtn').click(function (e) {
                var tbldata = tbltoarr();
                    data: $('#purchaseForm').serialize(),
                    url: "{{ route('') }}",
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                    error: function (data) {
                        var data2 = JSON.parse(data.responseText);
                        jQuery.each(data2.errors, function(key, value){

and Controller code is :

 public function store(Request $request)

$result = Purchase::updateOrCreate(['id' => $request->id],
    [   'date' => $request->date,
        'suppcode' => $request->code,
        'suppinv' => $request->invno,
        'suppdate' => $request->invdate,

        return response()->json(['success'=>'Account saved successfully.']);

tbldata is an array of items added to invoice, with following columns : Itemcode,Itemdesc,qty,rate,amount My question is how to attach tbldata to ajax post request and then how to handle/save it in controller.

Please sign in or create an account to participate in this conversation.