public function newPrescription() { $input = Input::all(); $pres = Prescription::where(DB::raw('DATE(created_at)'), '=', date('Y-m-d'))->where('patient', '=', $input['patient'])->first(); $isSell = 0; if (!Until::isNull($pres)) { if (Input::has('listDelete')) { PrescriptionDetail::whereIn('id', $input['listDelete'])->delete(); } else { if ($input['presSelect'] != $pres->id) { PrescriptionDetail::where('prescription', '=', $pres->id)->delete(); } } $isSell = $pres->is_sell; } else { $pres = new Prescription(); $pres->is_no_drug = false; } $pres->patient = $input['patient']; $pres->disease = $input['disease']; $pres->note = $input['note']; $pres->day = $input['dosage']; $pres->is_free = Until::isNull($input['isFree']) ? 0 : 1; $pres->is_repres = Until::isNull($input['isRe']) ? 1 : 0; $pres->is_sell = $isSell; $pres->save(); foreach ($input['drugs'] as $drug) { $detail = new PrescriptionDetail(); if (!Until::isNull($drug['idDetail'])) { $detail = PrescriptionDetail::where('id', '=', $drug['idDetail'])->first(); } $detail->prescription = $pres->id; $detail->drug = $drug['drugId']; $detail->price = Drug::where('id', '=', $drug['drugId'])->first()->price; switch ($drug['type']) { case 1: $detail->morning = $drug['morning']; $detail->lunch = $drug['lunch']; $detail->afternoon = $drug['afternoon']; $detail->night = $drug['night']; $detail->total = $drug['total']; break; case 3: $detail->special = $drug['dosage']; $detail->total = $drug['fixed']; case 2: case 4: $detail->total = $drug['fixed']; break; } $detail->save(); } return Response::json('true'); }
public function newDrug() { $input = Input::all(); $drug = new Drug(); if (Input::has('id')) { $drug = Drug::where('id', $input['id'])->first(); } else { $drug->type = $input['type']; } $drug->name = $input['name']; $drug->products = $input['products']; $drug->unit = $input['unit']; $drug->fixed = 1; switch ($drug->type) { case '1': $drug->morning = $input['morning']; $drug->lunch = $input['lunch']; $drug->afternoon = $input['afternoon']; $drug->night = $input['night']; break; case '2': case '3': case '4': $drug->special = $input['special']; break; default: break; } $drug->save(); return Response::json(array('drug' => $drug)); }