private void createBillFor(Customer customer) {
    List<CallEvent> customerEvents = new ArrayList<CallEvent>();
    for (CallEvent callEvent : callLog) {
      if (callEvent.getCaller().equals(customer.getPhoneNumber())) {
        customerEvents.add(callEvent);
      }
    }

    List<Call> calls = new ArrayList<Call>();

    CallEvent start = null;
    for (CallEvent event : customerEvents) {
      if (event instanceof CallStart) {
        start = event;
      }
      if (event instanceof CallEnd && start != null) {
        calls.add(new Call(start, event));
        start = null;
      }
    }

    BigDecimal totalBill = new BigDecimal(0);
    List<LineItem> items = new ArrayList<LineItem>();

    for (Call call : calls) {

      Tariff tariff = getCustomerTariff(customer);

      BigDecimal cost = calculateCost(call, tariff);
      totalBill = totalBill.add(cost);
      items.add(new LineItem(call, cost));
    }

    new BillGenerator(printer).send(customer, items, MoneyFormatter.penceToPounds(totalBill));
  }
Пример #2
0
 /**
  * Fired when a call ends
  *
  * @param evt CallEvent
  */
 public void callEnded(CallEvent evt) {
   AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
   if (audioMediaSession != null) {
     audioMediaSession.close();
   }
   VideoMediaSession videoMediaSession = evt.getSourceCall().getVideoMediaSession();
   if (videoMediaSession != null) {
     videoMediaSession.stopTrasmit();
     videoMediaSession.stopReceive();
   }
 }
Пример #3
0
  /**
   * Implements CallListener.incomingCallReceived. When a call is received creates a call panel and
   * adds it to the main tabbed pane and plays the ring phone sound to the user.
   */
  public void incomingCallReceived(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    CallPanel callPanel = new CallPanel(this, sourceCall, GuiCallParticipantRecord.INCOMING_CALL);

    mainFrame.addCallPanel(callPanel);

    if (mainFrame.getState() == JFrame.ICONIFIED) mainFrame.setState(JFrame.NORMAL);

    if (!mainFrame.isVisible()) mainFrame.setVisible(true);

    mainFrame.toFront();

    this.callButton.setEnabled(true);
    this.hangupButton.setEnabled(true);

    NotificationManager.fireNotification(
        NotificationManager.INCOMING_CALL,
        null,
        "Incoming call recived from: " + sourceCall.getCallParticipants().next());

    activeCalls.put(sourceCall, callPanel);

    this.setCallPanelVisible(true);
  }
Пример #4
0
  private void createBillFor(Customer customer) {
    List<CallEvent> customerEvents = new ArrayList<CallEvent>();
    for (CallEvent callEvent : callLog) {
      if (callEvent.getCaller().equals(customer.getPhoneNumber())) {
        customerEvents.add(callEvent);
      }
    }

    List<Call> calls = new ArrayList<Call>();

    CallEvent start = null;
    for (CallEvent event : customerEvents) {
      if (event instanceof CallStart) {
        start = event;
      }
      if (event instanceof CallEnd && start != null) {
        calls.add(new Call(start, event));
        start = null;
      }
    }

    BigDecimal totalBill = new BigDecimal(0);
    List<LineItem> items = new ArrayList<LineItem>();

    for (Call call : calls) {

      Tariff tariff = CentralTariffDatabase.getInstance().tarriffFor(customer);

      BigDecimal cost;

      DaytimePeakPeriod peakPeriod = new DaytimePeakPeriod();
      if (peakPeriod.offPeak(call.startTime())
          && peakPeriod.offPeak(call.endTime())
          && call.durationSeconds() < 12 * 60 * 60) {
        cost = new BigDecimal(call.durationSeconds()).multiply(tariff.offPeakRate());
      } else {
        cost = new BigDecimal(call.durationSeconds()).multiply(tariff.peakRate());
      }

      cost = cost.setScale(0, RoundingMode.HALF_UP);
      BigDecimal callCost = cost;
      totalBill = totalBill.add(callCost);
      items.add(new LineItem(call, callCost));
    }

    new BillGenerator().send(customer, items, MoneyFormatter.penceToPounds(totalBill));
  }
Пример #5
0
 // write log entry for all the small calls that are buffered so far
 private void flush() {
   if (collapsedCall == null) {
     return;
   }
   collapsedCall.logCall(
       CALL_COLLAPSED, null, new Object[] {callCount, byteCount}, getStreamId(), returnTime);
   reset();
 }
Пример #6
0
 /**
  * Fired when a call is received
  *
  * @param evt CallEvent
  */
 public void callReceived(CallEvent evt) {
   try {
     Call call = evt.getSourceCall();
     Interlocutor interlocutor = new Interlocutor();
     interlocutor.setCall(call);
     guiManager.addInterlocutor(interlocutor);
     call.addStateChangeListener(this);
     // handleAnswerRequest(interlocutor);
   } catch (Exception e) {
     Log.error("callReceived", e);
   }
 }
Пример #7
0
  /**
   * Implements CallListener.callEnded. Stops sounds that are playing at the moment if there're any.
   * Removes the call panel and disables the hangup button.
   */
  public void callEnded(CallEvent event) {
    Call sourceCall = event.getSourceCall();

    NotificationManager.stopSound(NotificationManager.BUSY_CALL);
    NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
    NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);

    if (activeCalls.get(sourceCall) != null) {
      CallPanel callPanel = (CallPanel) activeCalls.get(sourceCall);

      this.removeCallPanelWait(callPanel);
    }
  }
Пример #8
0
 public int OnCallEvent(CallEvent e) {
   return (getClass() == SipCallback.class)
       ? tinyWRAPJNI.SipCallback_OnCallEvent(swigCPtr, this, CallEvent.getCPtr(e), e)
       : tinyWRAPJNI.SipCallback_OnCallEventSwigExplicitSipCallback(
           swigCPtr, this, CallEvent.getCPtr(e), e);
 }
Пример #9
0
 // log a call that cannot be collapsed
 public synchronized void logCall(
     CallEvent event, int callIndex, Object returnValue, Object argValues[]) {
   flush();
   event.logCall(callIndex, returnValue, argValues, getStreamId());
 }