I am the predecessor of a routined programmer and understand the code but have some difficulties in finding the right syntax for the code and where to write in what way.
I have two forms (Lieferschein) and (Angebot) and can create a Lieferschein from Angebot. For this I copied
public function actionLieferscheinerstellen($id){…}
out of the LieferscheinController into AngebotController
When I want to create a Lieferschein out of an Angebot I click the corresponding button in the Indexview and a new actionLieferscheinerstellen is executed.
I would like to link Angebot with Lieferschein, so it is possible to say from which Angebot Lieferschein with (e.g.) lieferscheinNr = ‘17’ was generated.
For this I created a column in the table “lieferscheine” with the name angebotNrlieferschein.
I need a method which puts the corresponding angebotNr from the table “angebote” in angebotNrlieferschein so i can use theese numbers to show on the formulars from which Angebot said Lieferschein was generated.
lieferscheinNr is generated whith looking up max lieferscheinnr and adding 1 on it. This wouldnt work for angebotNr because there can be an old Angebot from which I want to generate a Lieferschein.
This is the code
public function actionLieferscheinerstellen($id)
{
if (($model = Recangeboten::findOne($id)) !== null)
{
$_max_plus_1=reclieferscheine::find()->select('Max(lieferscheinNr)+1 as nrxxx ')->asArray()->one();
$models = Recwarenangebot::find()
->where(" angeboten_id_angebot=".$id)
->all();
$modeleinstellung = Receinstellungen::findOne(['art' => 'Lieferschein']);
$_mx=$_max_plus_1['nrxxx'];
$_anrede="";
$_bemerkung="";
if($modeleinstellung !==null)
{
$_anrede=$modeleinstellung->anrede;
$_bemerkung=$modeleinstellung->bemerkung;
}
echo $_datum=Yii::$app->formatter->asDate(date('Y-m-d'));
$modelLieferschein = new Reclieferscheine();
$modelLieferschein->id_kunden=$model->id_kunden;
$modelLieferschein->datum=new yii\db\Expression('NOW()');
$modelLieferschein->lieferscheinNr=$_mx;
$modelLieferschein->title='';
$modelLieferschein->inhalt=$_anrede;
$modelLieferschein->bemerkung=$_bemerkung;
if($modelLieferschein->save(false))
{
$model=$this->findModel($id);
$model->istrechnung=1;
$model->save();
$lieferscheineid=$modelLieferschein->id_lieferscheine;
return Yii::$app->response->redirect(['reclieferscheine/update', 'id' => $lieferscheineid]);
}
else
{
echo "Not save";
}
}
}
I tried something like this
$modelLieferschein->angebotNr_lieferschein=$modelAngebot->angebotNr;
$modelRecverlinkung = new Recverlinkung();
$modelRecverlinkung->angebotNr_lieferscheinNr =$_mx;
didnt work though
Am thankful for any suggestions.
Best regards,
Kerem