Friday, May 18, 2018

Check duplication while uploading to database - development

Check duplication while uploading to database

I need to find duplicated details in the existing table while uploading a Excel file that contains some details,i need to find that by phone number and customer name. I am using mattexcel to upload the data into database.

I don’t want to insert that details if it is in there but other details must insert into that table

Controller

public function importExcel(Request $request)
    {
        if ($request->hasFile('import_file')) {
            Excel::load($request->file('import_file')->getRealPath(), function ($reader) {
                foreach ($reader->toArray() as $key => $row) {
                    $data['customername'] = $row['customername'];
                    $data['chassis'] = $row['chassis'];
                    $data['model'] = $row['model'];
                    $data['branchcode'] = $row['branchcode'];
                    $data['delivery'] = $row['delivery'];
                    $data['customerid'] = $row['customerid'];
                    $data['phone'] = $row['phone'];
                    $data['invoicedate'] = $row['invoicedate'];
                    $data['dse'] = $row['dse'];
                    $data['branch'] = $row['branch'];
                    $data['finance'] = $row['finance'];
                    $data['dono'] = $row['dono'];
                    $data['invoice'] = $row['invoice'];
                    $data['zsm'] = $row['zsm'];
                    $data['sm'] = $row['sm'];
                    $data['agm'] = $row['agm'];
                    $data['dsecode'] = $row['dsecode'];
                    $data['address'] = $row['address'];
                    $data['email'] = $row['email'];
                    $data['color'] = $row['color'];
                    $data['extendedwarrenty'] = $row['extendedwarrenty'];
                    $data['autocaddownload'] = $row['autocaddownload'];
                    $data['numberplate'] = $row['numberplate'];
                    $data['mcpstatus'] = $row['mcpstatus'];
                    $data['plandt'] = $row['plandt'];
                    $data['planok'] = $row['planok'];
                    $data['fasttag'] = $row['fasttag'];
//                    $data['settilment_pdf_path'] = $row['settilment_pdf_path'];
                    $data['rcstatus'] = $row['rcstatus'];
                    $branch = Branch::where([['branch_code', $row['branchcode']], ['status', 0]])->first();
                    $registration_id = Registration::orderBy('registration_id', 'desc')->take(1)->get();

                    if (count($registration_id) > 0) {
                        $regid = $registration_id[0]->registration_id;
                        $regid = $regid + 1;

                    } else {
                        $regid = 1;
                    }

                    $register = new Registration();
                    $register->registration_id = $regid;
                    $register->customername = $row['customername'];
                    $register->chassis = $row['chassis'];
                    $register->model = $row['model'];
                    $register->branchcode = $row['branchcode'];
                    $register->delivery = $row['delivery'];
                    $register->customerid = $row['customerid'];
                    $register->phone = $row['phone'];
                    $register->invoicedate = $row['invoicedate'];
                    $register->dse = $row['dse'];
                    $register->branch = $row['branch'];
                    $register->finance = $row['finance'];
                    $register->dono = $row['dono'];
                    $register->invoice = $row['invoice'];
                    $register->zsm = $row['zsm'];
                    $register->sm = $row['sm'];
                    $register->agm = $row['agm'];
                    $register->dsecode = $row['dsecode'];
                    $register->address = $row['address'];
                    $register->email = $row['email'];
                    $register->color = $row['color'];
                    $register->extendedwarrenty = $row['extendedwarrenty'];
                    $register->autocaddownload = $row['autocaddownload'];
                    $register->numberplate = $row['numberplate'];
                    $register->mcpstatus = $row['mcpstatus'];
                    $register->plandt = $row['plandt'];
                    $register->planok = $row['planok'];
                    $register->fasttag = $row['fasttag'];
                    $register->rcstatus = $row['rcstatus'];
                    $register->dealership = $branch->dealership_id;
                    $register->zone = $branch->zone_id;
                    $register->dh = $branch->dh_id;
                    $register->status = '0';
                    $register->created_user_id = Session::get('created_id');
                    $register->save();
                    $regidn = Registration::orderBy('registration_id', 'desc')->get();
                    $regidd = $regidn[0]->registration_id;

                    $ssitrack = new Ssi_track();
                    $ssitrack->registration_id = $regid;
                    $ssitrack->ssi_track_id = $regid;
                    $ssitrack->save();
                    $ssitrackk = Ssi_track::orderBy('ssi_track_id', 'desc')->get();
                    $ssitrackk = $ssitrackk[0]->registration_id;


                }
            });

        }
        return back()->with('success', 'Your File Is Successfully Uploaded To Database!');
    }



from Laravel Questions and Answers https://laravelquestions.com/php/check-duplication-while-uploading-to-database/
via Lzo Media

No comments:

Post a Comment